简体   繁体   中英

how to send a file from front end to back end with javascript or angularjs

some one knows how to send a file in an ajax request? my current problem is that i have the URL of the file in a

 <input type="file" />

but i don't know how to "load" the file in a variable or js object to can send it to my server

Can someone who has done this help me ? if there is any way to do it with AngularJS it would be great

Well you have two options to do so

  1. by converting to base64 but you can only send a max of 2mb data with it

  2. with form data, convert your data to multipart/form-data to do so you can use form data

     var formData = new FormData(); formData.append('file-name', $(file-content);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM