admin管理员组文章数量:1289391
Let's say I want to use some js encryption library (not java) to encrypt a file. Is it possible to do so on client side before sending the file to the server and so upload a file by javascript in some memory on client side ?
Could I use local storage for example at least for latest browsers ?
Let's say I want to use some js encryption library (not java) to encrypt a file. Is it possible to do so on client side before sending the file to the server and so upload a file by javascript in some memory on client side ?
Could I use local storage for example at least for latest browsers ?
Share Improve this question asked Jul 28, 2012 at 12:06 user310291user310291 38.2k86 gold badges294 silver badges518 bronze badges 1- yes you can...have a look at html5 file API! – Selvam Palanimalai Commented Jul 28, 2012 at 12:09
2 Answers
Reset to default 6You could use the File API
Here some examples: https://developer.mozilla/en/Using_files_from_web_applications)
Of course, as you imagined, you need latest browsers.
Yes you can. You have a few options to do that though.
Using FormData
const formData = new FormData()
formData.append('file', new Blob([fileTextContent], {type: 'text/plain'}))
await axios.post('/upload-file', formData)
Documentation: https://developer.mozilla/en-US/docs/Web/API/FormData/Using_FormData_Objects#creating_a_formdata_object_from_scratch
Set a file <input>
's value
let file = new File([data], "img.jpg",{type:"image/jpeg", lastModified:new Date().getTime()});
let container = new DataTransfer();
container.items.add(file);
fileInputElement.files = container.files;
Then you can submit the form containing the <input>
normally.
The code above is from this SO answer: https://stackoverflow./a/66466855/14366961
本文标签:
版权声明:本文标题:html - Is it possible to upload a file in memory using javascript for processing before sending it to server? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741400399a2376631.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论