html5 fileapi 二进制数据

发布于 2024-09-08 10:37:50 字数 166 浏览 7 评论 0原文

如果没有 fileReader 类,您可以从文件中获取二进制数据吗?我正在尝试上传文件,并且它可以在 firefox & 中运行。 chrome/webkit 但 safari 5 没有文件阅读器。

必须有一种方法来获取二进制数据,因为 gmail 具有在 safari 5 中工作的拖放功能。

Can you get the binary data from a file without the fileReader class? I'm trying to upload files and I have it working in firefox & chrome/webkit but safari 5 doesn't have filereader.

There has to be a way to get the binary data as gmail has drag and drop that works in safari 5.

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

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

发布评论

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

评论(2

吹梦到西洲 2024-09-15 10:37:50

我解决了,感谢这里的演示: http://webreflection.blogspot.com/2009/03/safari-4-multiple-upload-with-progress.html

我只需要提供数据传输文件...

var file = e.dataTransfer.files[0];

var xhr = new XMLHttpRequest();

xhr.open("POST", "upload_process.php", true);

xhr.send(file); //passing in file object seems to work

I worked it out, thanks to the demo here: http://webreflection.blogspot.com/2009/03/safari-4-multiple-upload-with-progress.html

I just need to feed the dataTransfer File...

var file = e.dataTransfer.files[0];

var xhr = new XMLHttpRequest();

xhr.open("POST", "upload_process.php", true);

xhr.send(file); //passing in file object seems to work
累赘 2024-09-15 10:37:50

我一直面临同样的问题,但我仍然不确定 xhr.send(file)。在使用 ASP.NET 时,我收到错误“检测到潜在危险数据......”。考虑到 FireReader 本身缺失,我认为 Safari 没有实现 xhr.send(file) 。

很高兴知道 xhr.send(file) 在 Safari 中可以工作。我会尝试进一步调查。

然而,有一个更好的替代方案,它可以很好地发挥 FormData 的作用。

var file = e.dataTransfer.files[0];
var xhr = new XMLHttpRequest();
xhr.open("POST", "upload_process.php", true);
var fd= new FormData(); //its supported in the safari, chrome and firefox 4
fd.append(file.name, file);
xhr.send(fd); //passing in file object seems to work

我现在还面临一个问题,Chrome 中的 HTML5 DataTransfer 检测错误 如果您遇到过此问题并找到任何解决方案,请告诉我。

I have been facing the same problem but i am still not sure about the xhr.send(file). As while using the ASP.NET i got the error "Potentially dangerous data is detected ... ". I thought xhr.send(file) is not implemented by Safari considering FireReader itself is missing.

Its nice to know that xhr.send(file) works in the Safari. I will try investigate it further.

However there is a better alternative for this which works great FormData.

var file = e.dataTransfer.files[0];
var xhr = new XMLHttpRequest();
xhr.open("POST", "upload_process.php", true);
var fd= new FormData(); //its supported in the safari, chrome and firefox 4
fd.append(file.name, file);
xhr.send(fd); //passing in file object seems to work

There is one more issue i am facing right now, its HTML5 DataTransfer detection error in Chrome please let me know in case you have faced and found any solution for this.

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