I am developing a web application with angularjs as the front-end and a CRUD service at the backend. One of the requirements is to allow the user to upload a csv file containing a list of items to be created. This can be implemented on the front-end by parsing the file in javascript and making create API call to the server for each item. However, I am an not sure if this approach is better than passing the file to the server and doing all the processing there. What are advantages/disadvantages of both these approaches? What is the common practice in such a scenario?
I am developing a web application with angularjs as the front-end and a CRUD service at the backend. One of the requirements is to allow the user to upload a csv file containing a list of items to be created. This can be implemented on the front-end by parsing the file in javascript and making create API call to the server for each item. However, I am an not sure if this approach is better than passing the file to the server and doing all the processing there. What are advantages/disadvantages of both these approaches? What is the common practice in such a scenario?
Share Improve this question edited Aug 4, 2015 at 13:52 vjain27 asked Aug 4, 2015 at 13:47 vjain27vjain27 3,6749 gold badges43 silver badges61 bronze badges 3 |3 Answers
Reset to default 11There are 4 things that I would use to make this decision:
Do you have very high load. If you parse it on the client you are using the clients CPU. Parsing it on the server could cost you by needing more CPU's.
Access to developer talent, is your team more productive programming it on the client or the server side.
If the answer to the above does not give a clear answer, then I would put it on the server side as it would be easier to test.
Will the "upload TSV" functionality be used by other parties/apps, who consume your API -- or is only the frontend using this functionality ?
Since I have implemented this scenario, couldn't resist from responding. I believe following things would be considered(Addition to points mentioned above) :
- The Size of the file, (Huge files freeze UI, no brainer) it can even crash some not so modern browsers.
- Does the file need parsing/sanitizing the contents?( you would not want the garbage to make its way to your server)
- Does the User need a feedback of the load summary details after the upload?(Aync vs Sync) - This tied back to #1
Regardless, you'll end up using some variation of the bulk copy at the backend.
Well I think its advisable to parse files at the backend. You get so many options like
- saving the file for reference
- reducing the load on your user's resource (RAM and CPU depending on the size of the file and the operation being done on the file before pushing to backend)
- Can re-initiate activity on file if there is an error during batch( if the error is code you can reproduce and help out client because you've got the file
http
request for every record and this would create useless http traffic. Of course, you could convertcsv
tojson
and send just this onejson
over one http request but since both are in fact simple text formats I would go with csv being processed on the server. EDIT: Also, if you're using e.g.sql server
you could dosql bulk insert
accordingly – Ivan Sivak Commented Aug 4, 2015 at 13:59