Action Script FileReference 对象可以发送到 Javascript 并转换为 File 对象吗?

发布于 2024-09-09 08:24:50 字数 302 浏览 1 评论 0原文

在动作脚本中,调用 FileReference.browse()。

我想将所选文件发送到 Javascript 并将其转换为 File 对象,就像我按下

我需要它能够显示图片缩略图,如此处所示。

也许可以只发送对象中缩略图所需的信息,而不是传递整个对象?

谢谢 !

In Action Script, FileReference.browse() is called.

I would like to send the chosen file to Javascript and convert it to File object, just like if I would press the Browse button of the <input type='file /> and got File object.

I need that to be able to display picture thumbnail like shown here.

Maybe instead of passing the whole object it is possible to send only the required information for the thumbnail from the object ?

Thanks !

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

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

发布评论

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

评论(2

因为看清所以看轻 2024-09-16 08:24:50

我认为没有任何方法可以创建 File 对象。例如,尝试以下操作:

var f = new File;

我收到异常“无法将 WrappedNative 转换为函数”。如果您查看File 的文档,会发现没有描述构造函数。此外,大多数属性都是只读的。我将其解释为只有浏览器才能创建 File 对象。

请记住,如果您可以通过指定文件路径来创建 File 对象,那么在未经用户同意的情况下上传文件将很容易。这将是一个严重的安全漏洞。

您可能会发现仅使用 Flash 或 HTML5 来实现此目的更为实用。

I don't think there is any way to create a File object. For example, try this:

var f = new File;

I get an exception "Cannot convert WrappedNative to function." If you look in the docs for File, there is no constructor described. Also, most of the attributes are read-only. I would interpret this to mean that only the browser can create a File object.

Keep in mind that if you could create a File object by specifying the path to a file, it would be easy to upload files without the user's consent. That would be a serious security hole.

You may find it more practical to use only Flash or only HTML5 for this.

菊凝晚露 2024-09-16 08:24:50

对于那些试图这样做的人来说。可以做的是:

  1. 将 fileReference 数据字节数组转换为 Base64 并将其放入字符串中
  2. 使用ExternalInterface 将此字符串发送到 javascript

我在想要概述二进制文件内容的上下文中使用此模式。即使是大图像也可以使用这种方法发送。然后可以使用具有适当 MIME 的数据 URI 在 javascript 中访问该文件:

data:image/png;base64,[data] 或 data:octet/stream,[data]

因为我是在 2 1/2 年后发布的第一篇文章,我们现在可以在所有流行的浏览器中做到这一点。

For people trying to do it. What can be done is:

  1. Converting the fileReference data byterray to Base64 and put it in a string
  2. Sending this string to javascript with ExternalInterface

I use this pattern in contexts where I want to have an overview of binary files content. Even a large image can be sent using this approach. The file can then be accessed in javascript using a data URI with the appropriate MIME:

data:image/png;base64,[data] or data:octet/stream,[data]

Since I'm posting almost 2 1/2 years after the first post, we can now do it in all popular browser.

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