使用的FileReader API麻烦上传二进制文件 [英] Trouble uploading binary files using FileReader api

查看:109
本文介绍了使用的FileReader API麻烦上传二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FileReader.readAsBinaryString使用的multipart / form-data发布请求到服务器上传文件。

I'm using FileReader.readAsBinaryString to upload a file using a multipart/form-data POST request to a server.

该文件被发送,服务器接收并保存该文件。

The file gets sent and the server receives and saves the file.

当我试图打开我得到的消息说,它已损坏(PNG图像),或者我看到一个空白文档(PDF中的情况下)的服务器上的文件。显然,事情错了。

When I try to open the file on the server I get messages saying that it is corrupted (png images) or I see a blank document (in the case of a pdf). Obviously something is going wrong.

是否有需要被应用到在FileReader.onload处理程序返回在event.target.result的数据的其他编码?我失去了什么东西?

Is there some other encoding that needs to be applied to the data returned in event.target.result in the FileReader.onload handler? Am I missing something else?

感谢

推荐答案

尝试使用 FORMDATA ,而不是读文件作为二进制字符串和构建的multipart / form-data的手动请求。看到这里我的回应: <一href="http://stackoverflow.com/questions/6133800/html5-file-api-readasbinarystring-reads-files-as-much-larger-different-than-file/6142797#6142797">HTML5文件API readAsBinaryString读取文件作为大得多,不是磁盘

Try using FormData instead of reading the file as a binary string and constructing the multipart/form-data request manually. See my response here: HTML5 File API readAsBinaryString reads files as much larger, different than files on disk

这篇关于使用的FileReader API麻烦上传二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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