我有一些java脚本函数。我正在使用输入类型文件来选择多个文件。在更改事件中,我获取已上传的文件对象列表,然后将这些对象存储在隐藏字段中。我只想将这些对象作为文件对象检索。我怎样才能做到这一点?
我使用的代码如下:-
<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
这是我发现对图像/文件存储有用的另一个来源:https://hacks.mozilla.org/2012/02/saving-images-and-files-in-localstorage/
希望对你有帮助!
关于javascript - 将 Json 对象转换为文件对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21882816/