Skip to content

Instantly share code, notes, and snippets.

@h-hub
Last active October 18, 2020 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-hub/d731f354d02483b1830a64262024c01e to your computer and use it in GitHub Desktop.
Save h-hub/d731f354d02483b1830a64262024c01e to your computer and use it in GitHub Desktop.
FileUploadController.java
@PreAuthorize("hasRole('ROLE_USER')")
@RequestMapping(value = "/image/upload", method = RequestMethod.POST, produces = { "application/json",
"application/xml" })
@ResponseBody
@ResponseStatus(code = HttpStatus.CREATED)
public ImageDto uploadImage(@RequestParam(value = "imageFile", required = true) @ValidateImg MultipartFile image) {
String bucketName = "public-bucket-for-files";
String imageUrl = imageService.uploadImage(image, bucketName);
ImageDto dto = new ImageDto();
dto.url = imageUrl;
return dto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment