Action Script FileReference 对象可以发送到 Javascript 并转换为 File 对象吗?
在动作脚本中,调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为没有任何方法可以创建 File 对象。例如,尝试以下操作:
我收到异常“无法将 WrappedNative 转换为函数”。如果您查看File 的文档,会发现没有描述构造函数。此外,大多数属性都是只读的。我将其解释为只有浏览器才能创建 File 对象。
请记住,如果您可以通过指定文件路径来创建 File 对象,那么在未经用户同意的情况下上传文件将很容易。这将是一个严重的安全漏洞。
您可能会发现仅使用 Flash 或 HTML5 来实现此目的更为实用。
I don't think there is any way to create a File object. For example, try this:
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.
对于那些试图这样做的人来说。可以做的是:
我在想要概述二进制文件内容的上下文中使用此模式。即使是大图像也可以使用这种方法发送。然后可以使用具有适当 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:
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.