+ 4

Reading / uploading file on web page

I want user to input a text file from his local storage to browser , then i want to read that file using JavaScript. how to do this? what should i learn ? can you explain with simple example? This is what I want to achieve 1> User selects a text file from his storage device 2> Read , verify and do some string operations on file using JAVASCRIPT 3> Create a JSON object by extracting text from file 4> Send JSON to server

10th Apr 2018, 6:10 PM
code learner
code learner - avatar
11 ответов
+ 6
You need server side scripts. You need a web server to run your project. Why not use php instead.
10th Apr 2018, 6:40 PM
Toni Isotalo
Toni Isotalo - avatar
+ 4
I can run nodejs server locally
11th Apr 2018, 4:36 AM
code learner
code learner - avatar
+ 4
This is what I want to achieve 1> User selects a text file from his storage device 2> Read , verify and do some string operations on file using JAVASCRIPT 3> Create a JSON object by extracting text from file 4> Send JSON to server
11th Apr 2018, 4:40 AM
code learner
code learner - avatar
+ 4
ok thanks @Morpheus I found something here :- https://www.html5rocks.com/tutorials/file/dndfiles/
11th Apr 2018, 7:58 AM
code learner
code learner - avatar
11th Apr 2018, 8:06 AM
code learner
code learner - avatar
+ 3
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data I have not done this yet but I ll try it myself too 👍 I ll post the progress soon
10th Apr 2018, 6:44 PM
Morpheus
Morpheus - avatar
+ 3
code learner , do you want to modify the file locally as well before converting it to json, I have few codes for that on nodejs, fs module will handle that file manipulation, rest JSON.stringify() and a post Operation will take care , I ll try to write it fresh with comments 👍
11th Apr 2018, 4:46 AM
Morpheus
Morpheus - avatar
+ 3
ok
11th Apr 2018, 8:44 AM
code learner
code learner - avatar
+ 2
code learner I made the complete stuff , i ll post the repo link , sorry for delay but using npm packages for everything made me so ignorant that I had to study again fir doing simple things, like request handling , body parsing etc 😅
11th Apr 2018, 8:00 AM
Morpheus
Morpheus - avatar
+ 1
yes html5 s file reader API , its awesome 👍
11th Apr 2018, 8:07 AM
Morpheus
Morpheus - avatar
+ 1
so , I m still trying to parse the post body at server side without any external libraries, hence you ll get clumsy raw data, will update the repo as I find a fix
11th Apr 2018, 8:42 AM
Morpheus
Morpheus - avatar