是否可以在幕后将文件转换为 FileReference?

发布于 2025-01-04 22:07:01 字数 334 浏览 2 评论 0原文

看来 FileReference.upload() 是您可以将文件上传到 Flash 中的服务器并通过 PROGRESS 回调获取有关其上传状态的反馈的唯一方法。所有其他方法只是进入以太坊并在文件上传完成后返回。

不幸的是,FileReference 似乎坚持要求用户选择要上传的文件。似乎没有一种机制可以通过代码设置文件。我需要这个的原因是我允许用户上传大量文件并分块上传它们,所以,我想将一大块数据打包到 FileReference (可能 5 或 10 兆)中并将其发送出去并看着它走。有人对是否可以手动将数据加载到 FileReference 对象有任何想法吗?遗憾的是,数据属性是只读的。对此的任何和所有建议都将得到善意对待:)

It would appear that FileReference.upload() is the only way in which you can upload a file to the server in Flash and get feedback about its upload state via a PROGRESS callback. All other methods just go off into the ether and come back when the file upload is completed.

Unfortunately, FileReference appears to insist that a user select the file to be uploaded. There doesn't appear to be a mechanism by which to set the file through code. The reason I need this is that I'm allowing the user to upload massive files and am uploading them in chunks, so, I want to just pack a chunk of data into a FileReference (maybe 5 or 10 megs) and send that off and watch it go. Does anyone have any thoughts on whether it's possible to manually load data into a FileReference object? The data property is read-only, sadly. Any and all advice on this will be treated with kindness :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不美如何 2025-01-11 22:07:01

发布者并不是尝试从用户系统上传随机文件,而是尝试获取文件引用来上传自定义数据 - 不幸的是,它不能。

我发现这个链接非常有帮助:
http://labs.findsubstance.com/2008/04/ 03/as3-上传-编码-图像/

The poster is not trying to upload random files from a users system, but rather trying to get file reference to upload custom data - which it unfortunately can't.

I found this link to be very helpful:
http://labs.findsubstance.com/2008/04/03/as3-upload-encode-images/

廻憶裏菂餘溫 2025-01-11 22:07:01

是的,这不应该是不可能的,这是一项安全措施。即,如果用户没有明确选择要发送的文件,您不应该能够从用户的 PC 发送随机文件。

但是,如果您设计不同,您可以监控上传。例如,您可以使用 URLStream 或 Socket 或 NetConnection 发送您想要的任何数据,并配置服务器以您需要的方式响应。例如,URLStream 提供了一个读/写流,可用于发送和接收数据。然后,您可以将其与某种缓冲区一起使用:发送缓冲区的内容,等待服务器确认已收到数据,重新填充缓冲区,然后重复。

编辑:所以我猜我们正在谈论 AIR 应用程序(因为您提到了文件)?那么,您可能正在使用 FileStream 打开一个文件,并希望使用 FileReference.upload() 发送刚刚收到的一大块数据 - 这是正确的吗?好吧,看来 FileReference 不能默默地做到这一点。尽管如此,我还是会使用 URLStream 将您想要上传的大数据块分割成 100 个部分,然后在从配置为接受它的服务器脚本接收到 OK 后发送每个部分。通常,文件上传由 HTTP 服务器直接处理,但您的情况需要一些额外的工作,即启动一个脚本来协商“包”大小、接收包并确认接收。对于可能超时的服务器脚本来说,这可能不那么简单,但肯定必须有一个解决方案。

或者,您可以将 HTTP 服务器配置为在收到套接字策略请求后提供套接字策略,之后,您可以与 Socket 连接并复制通常通过 FileReference 或类似 HTML 控件发送的多部分表单数据类型的请求。 (如果不是共享主机或其他任何会阻止我配置服务器的东西,我可能会选择这种方式)。

Yes, that shouldn't be possible, it's a security measure. I.e. you shouldn't be able to send random files from user's PC without users explicitly selecting them to be sent.

However, you can monitor the upload, if you design it differently. For instance, you could use URLStream or Socket or NetConnection to send any data you want and to configure the server to respond in a way you need. For example, URLStream provides a read/write stream that you can use for both sending and receiving the data. You could then use it with some sort of a buffer: send the content of the buffer, wait for the server to acknowledge the data was received, refill the buffer, repeat.

EDIT: So I'm guessing we are talking about AIR application (since you mention File)? So, you are probably opening a file using FileStream and wanting to send a chunk of data you just received by using FileReference.upload() - is that correct? Well, then it seems like FileReference cannot do it silently. Still, I would use URLStream to split the big chunk of data you want to upload into, say 100 parts and then send each part after receiving OK from the server script configured to accept it. Usually, file upload is handled directly by the HTTP server, but your case will require some extra work, namely, launching a script that would negotiate "package" size, receive the packages and acknowledge the reception. This may be less trivial for server scripts that might time out, but there certainly must be a solution to this.

Alternatively, you could configure your HTTP server to serve socket policy once it receives a socket policy request, afterwards, you could connect with the Socket and just copy the multipart-form-data kind of request usually sent through FileReference or similar HTML control. (I'd probably choose this way, if it wasn't a shared hosting or anything else that would prevent me from being able to configure the server).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文