繁体   English   中英

将大文件从nodejs上传到另一台服务器

[英]Uploading large files from nodejs to another server

我有一个使用node webkit的桌面应用程序,我需要能够将大文件从节点服务器上传到另一台服务器。 它需要能够将文件块化到服务器,因为有一个请求大小限制阻止流式传输整个文件。 我目前正在使用请求模块发布没有分块的上传,这适用于小文件,但我似乎无法找到任何关于如何从节点进行分块上传的示例。 以下是我现在所拥有的:

var form = request.post('http://server.com/Document/Upload',
    {contentType: 'multipart/form-data; boundary="' + boundaryKey + '"', preambleCRLF: true, postambleCRLF: true},
    function(err, res, body) {
        console.log(res);
    }).form();

form.append('uploadId', myUploadId);
form.append('file', fs.createReadStream(zipFileFullPath), {filename: 'test.zip'});

知道如何在节点中实现这一点吗? 我已经看到很多在节点服务器上接收分块上传的例子,但似乎无法找到关于如何从节点发送它们的任何内容。

查看文档以获取请求,它显示了如何提供chunked选项:

request({
    method: 'PUT',
    preambleCRLF: true,
    postambleCRLF: true,
    uri: 'http://service.com/upload',
    multipart: [
      {
        'content-type': 'application/json'
        body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
      },
      { body: 'I am an attachment' },
      { body: fs.createReadStream('image.png') }
    ],
    // alternatively pass an object containing additional options 
    multipart: {
      chunked: false,
      data: [
        {
          'content-type': 'application/json',
          body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
        },
        { body: 'I am an attachment' }
      ]
    }
  },
  function (error, response, body) {
    if (error) {
      return console.error('upload failed:', error);
    }
    console.log('Upload successful!  Server responded with:', body);
  })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM