0

I would like to know if AngularJS can save some file without need of NodeJS, PHP, Java or similar server side technology. Just pure JavaScript. I have seen many examples of AngularJS upload scripts. But it did not fully understood if AngularJS alone can do it. In those examples, files seem to be uploaded as blob, and then represented automaticly in browser when upload occurs. But that file or image is never saved on server, I mean on the disc of the server. I would like to achieve that.

I have checked this links: File Upload using AngularJS

AngularJS: how to implement a simple file upload with multipart form?

But seems or mentioned blob technique is used, or it is some server side technology involved. I would like to have upload script where I would not have to worry about server-side handling, so if possible, upload would be done all via AngularJS/JavaScript.

So can it be done, with pure AngularJS/JavaScript? I would appreciate the example..really don't know how to do this?

Community
  • 1
  • 1
DarioBB
  • 633
  • 2
  • 8
  • 26

1 Answers1

2

AngularJS is client side code only. By it self it has no power over the server from which it served. After the code is sent to your browser it has no connection or reference to the server side environment.

So the short answer is no.

The long answer is that you need a script/program running on your server which can handle the file input from a request. That request can be simple multi-part upload or a two way web socket connection, but anyway you need a logic which handles on the server side the request. Because Node.js server is written in JavaScript, you can write a full JavaScript implementation of file upload, but that's no longer just a simple AngularJS code.

G.T.
  • 432
  • 7
  • 17
  • Yeah, i know that about NodeJS, it would be great if AngularJS could use those NodeJS methods for actuall writting on disc – DarioBB May 03 '16 at 07:32
  • p.s. but that blob information could be saved to db for example, and then retrieved and anytime transformed into image (if it was image upload) ? Seems this could do the trick, just the images wouldn't be uploaded as files but as blob's in db directly. – DarioBB May 03 '16 at 07:35
  • 1
    Well unfortunately that's not going to happen any soon. That's not how HTTP and JavaScript is working. So the only solution for you is to write a simple server, I would suggest Express ( because of simplicity ) to handle the requests. The first thing google gives you if you search for it is this tutorial: http://code.ciphertrick.com/2015/12/07/file-upload-with-angularjs-and-nodejs/ I would try that one first. – G.T. May 03 '16 at 07:35
  • As I said, the AngularJS is only running on the client side, so it has no connection to the server/database or what so ever without you implementing a server side code and communication. This means the only system you can access from AngularJS is the clients machine and even that is limited, because of security reasons. So the only way of doing this is by writing some server side code in JavaScript or any other prefered language. – G.T. May 03 '16 at 07:37