Automattic / knox

S3 Lib
MIT License
1.74k stars 285 forks source link

Streaming files with putStream and Busboy #287

Closed voronianski closed 9 years ago

voronianski commented 9 years ago

In our api we were using Busboy+s3-upload-stream in order to upload files. Is it possible to achieve something similar with knox's putStream?

As an example, this is how it works with s3-upload-stream module:

const busboy = new Busboy({ headers: req.headers });
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
  // NOTE: file is ReadableStream

  const awsFileName = uuid.v4();

  // create writableStream
  const upload = s3UploadStream.upload({
    bucket: config.s3.bucket,  
    Key: awsFileName,
    ContentType: mimetype
  });

  file.on('uploaded', () => ...);
  file.on('error', () => ...);
  file.pipe(upload);
});

busboy.on('error', () => ...);

req.pipe(busboy);

There's a lack of docs regarding putStream method, does it accept only req/res as source of stream?