0

I really need your help. I have been looking for solution like 2 days. My question is how to properly select an image(s) FROM MY PC and upload (copy) that image on onother location ON MY PC?

For example:

In file chooser on my site i want to select an image(s) from C:/User/MyPC/Desktop/image_1 and then when i hit upload i want that image to be copied for example in D:/Java/Projects/MyProject

I would appreciate any help! Thank you so much in advance

  • Welcome to Stack Overflow! Try this article: https://stackoverflow.com/questions/15680629/mvc-4-razor-file-upload – Glenn Ferrie Sep 12 '18 at 12:36
  • Possible duplicate of [MVC 4 Razor File Upload](https://stackoverflow.com/questions/15680629/mvc-4-razor-file-upload) – Glenn Ferrie Sep 12 '18 at 12:36
  • That's currently a bit broad. Could you show some code/attempts and explain which problems you encountered? – Cleb Sep 12 '18 at 12:36
  • your image can only be uploaded to a (local) server. If your folder `MyProject` is a root directory, then it can be done with your REST API. You can simplify it with a use of [`ng-file-upload`](https://github.com/danialfarid/ng-file-upload) module. – Aleksey Solovey Sep 12 '18 at 12:44
  • Basically, you'd want to create a server with a angular GUI. With the angular GUI open in a browser, you'd want to use a file type input to upload a file to your server. Then, on the server side, you'd want to create some function to deposit the image where-ever you want it to end up in. Am I on the right track about what you want to do here? – Roope Sep 12 '18 at 12:54
  • @Roope That's right! Everything that I have tried did not help, I am stuck now and have to start again to code that part about uploading but do not know where and how to start. – MazZa Bre Sep 12 '18 at 12:59

1 Answers1

0

To upload an image to a server, the most bare-bones way is probably to just use a form:

<form action="your/upload/path/here">
  <input type="file" name="this-string-will-get-transferred-too">
  <input type="submit">
</form>

Then in whichever server system you are using, you would want to create some kind of handler to receive the HTTP request and the file sent by the form on clicking submit, and then use that server language's / framework's file API to save it where ever you please on your server machine.

This means that you will need to create the server-side code to handle the file and saving it, as well that you have to run the server on your local machine in order to save the file on your own file system, since browsers cannot as a rule save files to arbitrary locations in your file system.

Once you have the file transfer system set up, with the frontend browser portion sending files via some kind of file input, and the backend code for saving the file in a specific directory, you can naturally run the server software on your local machine to achieve the file move from C: => D: thing.

Good examples of receiving files server-side, for example with a Node.js server, can be found on the site: Node js receive file in HTTP request.

Roope
  • 291
  • 1
  • 8
  • I did something like this on server-side: @Path("upload") @POST @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.MULTIPART_FORM_DATA) public String upload() { return "Test"; } I tested on Postman, in Body I selected "binary", in Headers: Content-Type = multipart/form-data Now what should I put in upload(>HERE<) function and how to parse that multipart/form-data? – MazZa Bre Sep 12 '18 at 14:27
  • I'm assuming this is some java framework, unfortunately I'm not much of a java guy and can't really help there. Searching other questions related to handling file uploads in your specific framework should yield results you can adapt though! – Roope Sep 12 '18 at 14:38