Wednesday, 5 April 2017

File upload from NodeJS to Java Spring framework

I need a simple File Upload (JavaScript code example) from NodeJS to Java Spring framework method as followed.

Any help (approach) would be very much appreciated !

Java Code in Spring framework:

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ResponseEntity<FileJobResultBase> upload(HttpServletRequest httpServletRequest
) throws IOException {
    try {
        String storageName = httpServletRequest.getHeader("storageName");
        String path = httpServletRequest.getHeader("path");
        String fileName = httpServletRequest.getHeader("fileName");
        String fileType = httpServletRequest.getHeader("fileType");
        String context = httpServletRequest.getHeader("context");
        String organization = httpServletRequest.getHeader("organization");
        byte[] bytes = IOUtils.toByteArray(httpServletRequest.getInputStream());
        FileJobResultBase fileJobResultBase = fileManagerService.upload(bytes, storageName, path, fileName, fileType == null ? "unknown" : fileType,authorization,organization, context);
        return new ResponseEntity<>(fileJobResultBase, HttpStatus.OK);
    } catch (Exception e) {
        return  exceptionHandling( e);

    }


}



via EfiBN

No comments:

Post a Comment