问题
Where do I specify the format or pattern for the server name that FineUploader creates when uploading to Amazon S3? I need to have greater control over how the file name and path is created on S3. Thanks.
回答1:
Use the objectProperties.key option.
You can provide a String
value or a function that returns the intended key as a String
.
The following example demonstrates setting a key and performing a blocking action ($.post
). It uses the jQuery plugin,
// <snip>
objectProperties: {
key: function(fileId) {
var keyRetrieval = new qq.Promise(),
filename = $("#fineUploader").fineUploader("getName", fileId);
$.post("createKey.html", {name: filename})
.done(function(data) { keyRetrieval.success(data.key); })
.fail(function() { keyRetrieval.failure(); });
return keyRetrieval;
}
},
// </snip>
A simpler example,
objectProperties: {
key: function(fileId) {
var filename = $("#fineUploader").fineUploader("getName", fileId);
return fileId + "/" + filename;
}
},
Keep in mind that you should make these keys unique if you want to prevent users from overwriting each others' files! Putting each upload in a folder with a random key would prevent this.
来源:https://stackoverflow.com/questions/19335791/fineuploader-with-s3-how-to-specify-object-name-on-s3