使用S3的FineUploader如何在S3上指定对象名称 [英] FineUploader with S3 how to specify object name on S3

查看:158
本文介绍了使用S3的FineUploader如何在S3上指定对象名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上载到Amazon S3时,我在哪里指定FineUploader创建的服务器名称的格式或模式?我需要更好地控制如何在S3上创建文件名和路径.谢谢.

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.

推荐答案

使用 objectProperties.key 选项.

您可以提供一个 String 值或一个将所需键作为 String 返回的函数.

You can provide a String value or a function that returns the intended key as a String.

下面的示例演示了设置键和执行阻止操作( $.post ).它使用jQuery插件,

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>

一个简单的例子,

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.

这篇关于使用S3的FineUploader如何在S3上指定对象名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆