摘要
基于传统的HTML5多文件上传采用FormData方式,将文件数据编译成键值对,用异步请求方式上传文件,但是不同浏览器对FormData对象的支持情况并不容乐观,导致不支持FormData的浏览器文件上传失败。该文针对浏览器不支持FormData对象操作,提出在基于浏览器客户端对图片进行Base64编码,将图片转换为字符串提交,在服务器端再对其进行解码后再生成图片文件的通用图片上传方法。
Based on the traditional HTML5 multi-file uploading method, the file data is compiled into key-value pairs and upload-ed asynchronously. However, the support of different browsers for FormData objects is not optimistic, which leads to the failure offile uploading in browsers that do not support FormData. In view of the fact that browsers do not support the operation of FormDataobjects, this paper proposes a general image uploading method based on browser client to encode pictures by Base64, convert pic-tures to string submission, decode them on the server and regenerate them into picture files.
引文
[1]刘耀钦.利用HTML5拖放技术实现多文件异步上传[J].四川理工学院学报:自然科学版, 2015(1):1673-1549.
[2]糜梅.基于HTML5的文件上传类设计[J].电脑知识与技术,2015(2):1009-3044.
[3]王莉敏.基于HTML5大文件断点续传的实现方案[J].计算机与现代化, 2016(3):1006-2475.
[4] Joker_Ye. HTML5实现图片压缩上传功能[EB/OL]. https://blog.csdn.net/hj7jay/article/details/51003926.