如何获得网址上传的文件? [英] How to get URL to uploaded file?

查看:177
本文介绍了如何获得网址上传的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地将文件上传到S3。

不过我有麻烦试图让被上载的文件的URL。

我看到有一个getKey方法,但它似乎并没有工作,我想。

从本质上讲,我试图取代一个链接到上传的文件中列出的文件的名称。没用上载文件,如果上传人无法获得一个链接到它。

所以,我一直在试图让上传对象的URL或钥匙,并已打算修改的完整的事件中的文件名的文本。

也许有更好的方法来修改的最终文件名的文本。

下面是似乎是我不工作:

 })。在('完成',函数(事件,ID,姓名,responseJSON){

    //失败,没有使用fineuploader对象正确,manualuploader是fineuploader对象。
    的console.log(对象键:+ manualuploader.getKey(ID));

    });
 

解决方案

您有两种选择:

  1. 获取签署的网址通过AWS SDK服务器端的文件和你的回应精细上传的uploadSuccess请求返回的URL。这将提供给通过响应参数的完整的事件处理程序。

  2. 构建URL的客户端使用的密钥和水桶URL。

您必须使用选项1,如果你的文件不公开查看。在fineuploader.com该演示使用选项1,在大多数情况下,这是最合适的方法,除非你确定允许任何人从你的水桶流文件多,因为他们想要永远。

另外,如果你正在试图调用 getKey 法,或使用jQuery插件时,任何其他方法,在精细上传实例,你必须这样做如jQuery插件文档描述。你调用 getKey 在code以上方法是不符合的文件一致。您需要调用getKey这样的: $(#上传)fineUploaderS3(getKey,ID)

I am successfully uploading files to S3.

However I am having trouble trying to get the URL of the file that was uploaded.

I see there is a getKey method, but it does not seem to work as I thought.

Essentially I am trying to replace the name of the file listed with a link to the uploaded file. Useless uploading a file if the person uploading cannot get a link to it.

So I have been trying to get the URL or key of the uploaded object, and have been planning on modifying the filename text in the 'complete' event.

Perhaps there is a better way to modify the final filename text.

Here is what I does not seem to work:

    }).on('complete', function (event, id, name, responseJSON) {

    // Fails, not using the fineuploader object correctly, manualuploader is the fineuploader object.
    console.log("Object Key:+manualuploader.getKey(id));

    });

解决方案

You have two options:

  1. Obtain a signed URL for the file via the AWS SDK server-side and return the URL in your response to Fine Uploader's uploadSuccess request. It will be made available to your "complete" event handler via the response param.

  2. Construct the URL client-side using the key and bucket URL.

You must use option 1 if your file is not publicly viewable. The demo on fineuploader.com uses option 1. In most cases, this is the most appropriate approach, unless you are ok allowing anyone to stream the files from your bucket as much as they want forever.

Also, if you are trying to call the getKey method, or any other method, on a Fine Uploader instance when using the jQuery plug-in, you must do so as described in the jQuery plug-in documentation. Your call to the getKey method in your code above is not consistent with the documentation. You would need to call getKey like this: $("#uploader").fineUploaderS3("getKey", id).

这篇关于如何获得网址上传的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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