2017-03-06 33 views
1

我已經在回送3一個非常簡單的服務器上運行,並再次遇到這個問題:https://github.com/strongloop/loopback-component-storage/issues/9迴環3環回分量存儲掛在POST文件

由於學家和實例不工作下去我會喜歡重新開放這個問題。 我創建了一個非常簡單的API模板服務器,並添加以下代碼:

module.exports = function (File) { 
    File.upload = function (ctx, options, cb) { 
     if (!options) options = {}; 
     ctx.req.params.container = 'common'; 

     console.log("DO"); 
     File.app.models.Storage.upload(ctx.req, ctx.result, options, function (err, fileObj) { 
      console.log("FILE"); 
      cb(fileObj); 

     }); 
    }; 

    File.remoteMethod(
     'upload', 
     { 
      description: 'Uploads a file', 
      accepts: [ 
       {arg: 'ctx', type: 'object', http: {source: 'context'}}, 
       {arg: 'options', type: 'object', http: {source: 'query'}} 
      ], 
      returns: { 
       arg: 'fileObject', type: 'object', root: true 
      }, 
      http: {verb: 'post'} 
     } 
    ); 

}; 

現在的問題是,儘管通過郵差張貼到上傳的功能,我在控制檯看到以下行爲:

DO 
Error: Request aborted 
    at IncomingMessage.<anonymous> (...../server/node_modules/formidable/lib/incoming_form.js:120:19) 
    at emitNone (events.js:86:13) 
    at IncomingMessage.emit (events.js:188:7) 
    at abortIncoming (_http_server.js:383:9) 
    at socketOnClose (_http_server.js:377:3) 
    at emitOne (events.js:101:20) 
    at Socket.emit (events.js:191:7) 
    at TCP._handle.close [as _onclose] (net.js:504:12) 
FILE 

和送信返回一個空的響應...

我完全失去了在這裏當初學者在這一步!

這是我的錯嗎?

THX對於任何輸入

回答

1

OMG,看來我已經找到了答案:

https://github.com/strongloop/loopback-component-storage/issues/86

只需使用標頭 「接受」 與價值 「的multipart/form-data的」,而不是設置「內容類型」。這對我來說適用於Postman

+0

我現在還提交了一個錯誤...也許有人在IBM會修復此問題:https://github.com/strongloop/loopback-component-storage/issues/196 – PArt

+0

你提交郵遞員的文件輸入?作爲二進制或表單數據?你能展示一個輸入的例子嗎? –