FineUploader with S3 how to specify object name on S3

Deadly 提交于 2021-01-29 08:24:27

问题


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

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