Fine Uploader to S3 Folder

2019-07-07 04:12发布

Does anyone know if it's possible to upload to a folder inside an S3 bucket using Fine Uploader? I have tried adding a '\foldername' to the request endpoint but had no luck with that.

Thanks.

4条回答
贪生不怕死
2楼-- · 2019-07-07 04:54

This works for me:

var uploader = new qq.s3.FineUploader({
    // ...
    objectProperties: {
        key: function(fileId) {
            return 'folder/within/bucket/' + this.getUuid(fileId);
        }
    }
});
查看更多
Root(大扎)
3楼-- · 2019-07-07 05:04
$("#fineuploader-s3").fineUploaderS3({
    // ....
    objectProperties: {
        key: function (fileId) {

            var filename = $('#fineuploader-s3').fineUploader('getName', fileId);
            var uuid = $('#fineuploader-s3').fineUploader('getUuid', fileId);
            var ext = filename.substr(filename.lastIndexOf('.') + 1); 

           return  'folder/within/bucket/' + uuid + '.' + ext;
        }
    }
});
查看更多
趁早两清
4楼-- · 2019-07-07 05:09

S3 doesn't have folders. Some UIs (such as the one in the AWS console) and higher-level APIs may provide this concept, as an abstraction, but S3 doesn't have any native understanding of folders, only keys. You can create any key you want and pass it along to Fine Uploader S3, it will store that file given that specific key. For example, "folder1/subfolder/foobar.txt" is a perfectly valid key name. By default, Fine Uploader generates a UUID and uses that as your object's key name, but you can easily change this by providing an objectProperties.key value, which can also be a function. See the S3 objectProperties option in the documentation for more details.

查看更多
干净又极端
5楼-- · 2019-07-07 05:13

You can modify the path before upload to the server:

uploader.on('submit', (id) => {   
  const key = s3Uploader.methods.getUuid(id)   
  const newkey = 'folder/within/bucket/' + key   
  uploader.methods.setUuid(id, newkey) 
})
查看更多
登录 后发表回答