Node SDK - download public shared file

新規投稿

コメント

3件のコメント

  • Miroku_87

    For the moment I've used this solution:

    var fs         = require("fs"),
        request    = require("request");
    
    function downloadFile(source, target, callback)
    {
        var wr = fs.createWriteStream(target);
        
        wr.on("error", function (err) {
            callback(err);
        });
        
        wr.on("close", function (ex) {
            callback();
        });
    
        request
            .get(source)
            .on("error",function(err){
                callback(err);
            })
            .on('response', function(response) 
            {
                if((""+response.statusCode).charAt(0) != "2")
                    callback({
                            msg: "File not found: "+response.request.href, 
                            path: response.request.href,
                            toString: function(){
                                return this.msg;
                            }
                         });
            })
            .on("end", function (ex) {
                console.log("request ended");
            })
        .pipe(wr)
    }
    
    function onDownloadComplete(err)
    {
        if(err)
            throw err
        
        console.log("DOWNLOAD COMPLETE");
    }
    
    function init()
    {
        var static_url = process.argv[2].replace(/\/s\//,"/shared/static/") + ".zip";
        
        downloadFile(static_url, "./output/file.zip", onDownloadComplete);
    }
    
    init();

    Hope this will help others.

    0
    コメントアクション パーマリンク
  • wjakahi

    Trying to do what you're doing.  This link shows how to get the file id.

    https://github.com/box/box-node-sdk/blob/master/docs/shared-items.md

     

    once i get the file id, I still get "not found" when trying to get the file tho.

     

    HTH

    0
    コメントアクション パーマリンク
  • wjakahi

    Just got it to work, but not with the anonymous client.  switched that line to using a developer key and it worked.  Something with anonymousclient.

     

      //var client = sdk.getAnonymousClient();
      var client = sdk.getBasicClient('');
    0
    コメントアクション パーマリンク

サインインしてコメントを残してください。