将Json对象转换为文件对象 [英] Convert a Json Object to a file Object
问题描述
我有一些Java脚本功能.我正在使用输入类型文件来选择多个文件.在变更事件中,我得到了一个列表文件对象,这些对象已上传,然后将这些对象存储在隐藏字段中.我只想将这些对象检索为文件对象.我该怎么办?
I have some java-script functions. I am using input type file for selecting multiple files. In the on-change event I am getting a list files objects which were uploaded and then I am storing those objects in a hidden field. I want to retrieve those objects as file objects only. How can i accomplish that?
我正在使用的代码如下:-
The code I am using is as follows:-
<input type="file" multiple onchange="ehDisplayFileNames(event);" />
function ehDisplayFileNames(event) {
myFilesList = $('#' + event.target.id)[0]; // $('#chooseFiles')[0] gives the DOM element of the HTML Element as opposed to $('#store-input') which gives the jQuery object
$("#FilesToUpload").val(JSON.stringify(filesToUpload));
}
function getAllFiles(){
var filesToUpload = [];
filesToUpload = $.parseJSON($("#FilesToUpload").val()); // returns json objects instead i need file objects
}
谢谢您的帮助.
推荐答案
我一直在寻找类似的东西.我最终使用了此处提供的解决方案,因为无法序列化API对象... https://stackoverflow.com/a/20535454/606810
I was looking for a similar thing.. I ended up using the solution provided here as there is no way to serialize API object... https://stackoverflow.com/a/20535454/606810
这是我发现对图像/文件存储有用的另一个来源: https://hacks.mozilla.org/2012/02/saving-images-and-files-in-localstorage/
Here is another source i found useful for image/file storage: https://hacks.mozilla.org/2012/02/saving-images-and-files-in-localstorage/
希望有帮助!
这篇关于将Json对象转换为文件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!