P
P
prizrak392017-04-17 18:23:06
Java
prizrak39, 2017-04-17 18:23:06

How to properly check the file download service?

Good afternoon.
There is a service for downloading a file and data at the same time in one method (maybe that's wrong).

@RequestMapping(value = "/uploadFile", method = RequestMethod.POST, produces = "application/json", consumes="multipart/form-data")
    @ResponseBody
    public ResponseEntity<String> uploadFile(@RequestPart("file") MultipartFile multipartFile,
                                             @RequestBody Users users) {

        if (multipartFile == null)
            return new ResponseEntity<String>("Error", HttpStatus.NOT_FOUND);
        String strPath = Utils.createDirectoryToUser(users);
        if (strPath == null) {
            return new ResponseEntity<String>("Error", HttpStatus.INTERNAL_SERVER_ERROR);
        }

        try {
            int read = 0;
            File newFile = new File(strPath + "/" + multipartFile.getName());

            FileOutputStream fos = new FileOutputStream(newFile);
            CountingOutputStream out = new CountingOutputStream(fos);
            byte[] bytes = new byte[1024];

            while ((read = multipartFile.getInputStream().read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new ResponseEntity(strPath + "/" + multipartFile.getName(), HttpStatus.OK);
    }

I'm trying to test a service call locally using POSTMAN.
When choosing the form-data call format, error 415.
Please tell me how to properly check the call using POSTAMAN.
It is also possible that it is wrong to pass a file and data in one method.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question