I would like to upload multiple JSON files (like student grades JSON, and student courses schedule JSON, student assignment JSON etc) and metadata (like student information)
To Rest service running on Jersy and tomcat
What is the approach to take here? should it be like a single controller? is it possible to specify the uploaded JSOn structure? what if one of the files is missing?
@Path("/submitStudentInformation")
public class SubmitStudInfoController {
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
@Path("/multipleFiles")
public Response uploadFiles(@Context HttpServletRequest request) {
@POST
@Path("/uploadFile")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response uploadFile(@FormDataParam("files") List<FormDataBodyPart> files)
if(files!=null) {
for (int i = 0; i < files.size(); i++) {
FormDataBodyPart this_formDataBodyPartFile = files.get(i);
ContentDisposition this_contentDispositionHeader = this_formDataBodyPartFile.getContentDisposition();
InputStream this_fileInputStream = this_formDataBodyPartFile.getValueAs(InputStream.class);
FormDataContentDisposition fileDetail = (FormDataContentDisposition) this_contentDispositionHeader;
String imagename = fileDetail.getFileName();
}
}
var formdata = new FormData();
$scope.getTheFiles = function(element) {
$scope.$apply(function($scope) {
$scope.files = element.files;
for (var i = 0; i < element.files.length; i++) {
formdata.append('files', element.files[i]);
}
});
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With