问题
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