2015-05-20 48 views
0

我試圖使用Filepicker API和request.js模塊將文件上傳到S3。分段上傳後文件內容不正確

content = "ABCDEF" 
options = 
    url: 'https://www.filepicker.io/api/store/S3' 
    preambleCRLF: true # tried also with false 
    postambleCRLF: true # tried also with false 
    qs: 
    key: 'XXX' 
    store: 'S3' 
    mimetype: 'text/csv' 
    path: 'some-path.csv' 
    container: 'my-bucket' 
    access: 'public' 
    multipart: [ 
     { 
     body: content 
     } 
    ] 
    method: 'post' 

request options, (err, res, body) -> 
    # 200 OK 

它通常工作然而上傳的文件內容是這樣的:

--6f63ec28-40de-425c-86d5-36f0befcec4a 
ABCDEF 
--6f63ec28-40de-425c-86d5-36f0befcec4a-- 

我在做什麼錯?

回答

1

這個請求的主要問題是你已經把multipart選項放在querystring參數中。這對我有效的請求是:

request = require("request"); 
    content = "ABCDEF"; 
    options = { 
    url: 'https://www.filepicker.io/api/store/S3', 
    preambleCRLF: true, 
    postambleCRLF: true, 
    multipart: [ 
     { 
      body: content 
     } 
     ], 
    method: 'post', 
    qs: { 
     key: 'APIKEY', 
     store: 'S3', 
     mimetype: 'text/csv', 
     path: 'some-path.csv', 
     access: 'public', 
    } 
    }; 

    request(options, function(err, res, body) { 
     console.log(res.statusCode); 
     console.log(body); 
    });