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);
}
}
Aggregations