Uploadify uploading arbitrary file to s3 with corr

2019-08-21 11:33发布

问题:

I need to be able to upload any file type, for example, both pdf and jpeg. S3 requires the content-type be set at the time of upload, or the file will not be served correctly

Is it possible to dynamically assign the content-type in the onSelect callback or elsewhere?

The content-type is set in the postData parameter to uploadify (scriptData in older uploadify versions). Right now I have no way to set this until a file is selected. After the file is selected I could determine (mostly accurately) the content-type from the file extension. Now all files are served as application/octet-stream, which makes them pretty useless.

回答1:

You can set the metadata including content-type of an existing S3 object by copying the object to itself and specifying the new data.



回答2:

This can be accomplished using uploadifySettings() in a callback:

  • onUploadStart seems to work fine in 3.0.0. In 2.x, this was called onOpen and the documentation says that it did not work.

  • onSelect works with single files, but not with multiple files of different types because the selection events are called at the same time