2015-06-10 84 views
-1

不知道我在這裏做錯了什麼......我試圖從nodejs上使用knox庫上傳視頻(多部分)從android到AmazonS3時不斷收到此錯誤...我正在使用異步庫以及等待影片完成上傳之前,我調用回調(CB)的下一個功能這裏是我的錯誤:繼續收到函數錯誤不知道爲什麼

2015-06-10T08:32:27.877193+00:00 app[web.1]: stream.on('error', fn); 
2015-06-10T08:32:27.877195+00:00 app[web.1]:  ^
2015-06-10T08:32:27.877196+00:00 app[web.1]: TypeError: undefined is not a function 
2015-06-10T08:32:27.877198+00:00 app[web.1]:  at Client.putStream (/app/node_modules/knox/lib/client.js:448:10) 
2015-06-10T08:32:27.877200+00:00 app[web.1]:  at setupAndCreateImage (/app/routes/challenge.js:397:11) 
2015-06-10T08:32:27.877201+00:00 app[web.1]:  at fn (/app/node_modules/async/lib/async.js:582:34) 
2015-06-10T08:32:27.877202+00:00 app[web.1]:  at Immediate._onImmediate (/app/node_modules/async/lib/async.js:498:34) 
2015-06-10T08:32:27.877204+00:00 app[web.1]:  at processImmediate [as _immediateCallback] (timers.js:358:17) 

下面是代碼:

function setupAndCreateImage (cb) { 
      if(req.files && req.files.mediaFile) { 
       console.log("Received file:\n" + JSON.stringify(req.files)); 

        //add p for pics will do v for vids 
        videoID = "v" + path.basename(req.files.mediaFile.path); 
        tmp_path = req.files.mediaFile.path; 
        //targetPathSmall = './public/img/challenges/' + videoID; 
        //videoConvert = req.files.mediaFile.name; 


        var video = req.files.mediaFile; 
        var s3Headers = { 
         'Content-Type': video.type, 
         'Content-Length': video.size, 
         'x-amz-acl': 'public-read' 
        }; 
          //console.log('stdout:', stdout, targetPathSmall) 
          s3.putStream(tmp_path, videoID, s3Headers, function(err, s3response){ 
           //handle, respond 
           if(err) { 
            console.log(err); 
           } else { 
            s3response.resume(); 
            console.log("saved to S3"); 
            //console.log(s3response); 
            cb(null, videoID); 
           } 
          }); 
         } else { 
          videoID = ""; 
          cb(null, videoID); 
         } 

        }, 

回答

1

你」重傳一個字符串作爲第一個參數到s3.putStream期望Stream的地方。

https://github.com/Automattic/knox/blob/master/lib/client.js#L398

您應該使用它像這樣:

s3.putStream(inputStream, videoID, s3Headers, function(err, s3response) { 

您可以通過閱讀req.mediaFile的內容流,以填充inputStream如果可能的話。從代碼中很難說清楚。

祝你好運!

相關問題