I am using ng-file-upload to send files to server.ng-file-upload worked perfectly with upload file one by one.I am using latest chrome browser.
Sample code snippet
in there files are uploaded to the server when files are selected in the file input.But what i want is that files (selected file array) should be uploaded only to the server when submit button is clicked along with other form data.
Jersey REST service
@POST
@Path("/manual")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public boolean insertResults(@FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("file") FormDataContentDisposition fileDetail,@FormDataParam("username") String username) throws IOException {
System.out.println(username);
StringWriter writer = new StringWriter();
IOUtils.copy(uploadedInputStream, writer,"UTF-8");
String theString = writer.toString();
System.out.println(theString);
return Boolean.TRUE;
}
I am new to AngularJs stuff please help me to overcome this problem.
I have decided to write a descriptive answer about how to send multiples files to back end and access file details one by one.There are lack of informative answers are on the internet regarding this so this answer maybe helpful for someone.To send multiple files in AngularJs to back end you can use ng-file-upload API.You can send files when submit button click like above mentioned answer.Let assume your front end is working perfectly and can send files to server.So most of you have doubt about how to manipulate files and other details if it is a multipart form data.Here is the way how to manipulate form data.
Server end received data something like below.
Sample files data along with other form attributes
REST endpoint(using Jersey) to manupulate multipart form data
According to the documentation on the site and from what I'd expect - you can attach the upload function to the button and trigger it as you'd do any other function. This is an example from the GitHub documentation on ng-file-upload:
Here you can see that he's calling the $scope.upload function when the forms $scope.submit is called plus he's even checking to see if the form is valid before calling upload.