Fine Uploader to S3 Folder

*爱你&永不变心* 提交于 2019-12-10 21:06:44

问题


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.


回答1:


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.




回答2:


This works for me:

var uploader = new qq.s3.FineUploader({
    // ...
    objectProperties: {
        key: function(fileId) {
            return 'folder/within/bucket/' + this.getUuid(fileId);
        }
    }
});



回答3:


$("#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:


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) 
})


来源:https://stackoverflow.com/questions/19988879/fine-uploader-to-s3-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!