Difference between upload() and putObject() for uploading a file to S3?

前端 未结 3 1514
梦如初夏
梦如初夏 2020-12-07 22:35

In the aws-sdk\'s S3 class, what is the difference between upload() and putObject()? They seem to do the same thing. Why might I prefer one over the other?

3条回答
  •  佛祖请我去吃肉
    2020-12-07 23:06

    upload() allows you to control how your object is uploaded. For example you can define concurrency and part size.

    From their docs: Uploads an arbitrarily sized buffer, blob, or stream, using intelligent concurrent handling of parts if the payload is large enough.

    One specific benefit I've discovered is that upload() will accept a stream without a content length defined whereas putObject() does not.

    This was useful as I had an API endpoint that allowed users to upload a file. The framework delivered the file to my controller in the form of a readable stream without a content length. Instead of having to measure the file size, all I had to do was pass it straight through to the upload() call.

提交回复
热议问题