Search in sources :

Example 1 with ModelApiResponse

use of org.springdoc.demo.app2.model.ModelApiResponse in project springdoc-openapi-demos by springdoc.

the class PetApiDelegateImpl method uploadFile.

@Override
public ResponseEntity<ModelApiResponse> uploadFile(Long petId, String additionalMetadata, MultipartFile file) {
    try {
        String uploadedFileLocation = "./" + file.getName();
        System.out.println("uploading to " + uploadedFileLocation);
        IOUtils.copy(file.getInputStream(), new FileOutputStream(uploadedFileLocation));
        String msg = String.format("additionalMetadata: %s\nFile uploaded to %s, %d bytes", additionalMetadata, uploadedFileLocation, (new File(uploadedFileLocation)).length());
        ModelApiResponse output = new ModelApiResponse().code(200).message(msg);
        return ResponseEntity.ok(output);
    } catch (Exception e) {
        throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Couldn't upload file", e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ModelApiResponse(org.springdoc.demo.app2.model.ModelApiResponse) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseStatusException(org.springframework.web.server.ResponseStatusException) ResponseStatusException(org.springframework.web.server.ResponseStatusException)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ModelApiResponse (org.springdoc.demo.app2.model.ModelApiResponse)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1