I have an Angular webapp that uses a Spring Boot REST service as its backing web service.
I am adding a "Profiles" feature for users, and as part of this I want to stand up an endpoint that allows users to upload profile images for themselves and immediately upload those files to S3 (where I will host all the images from).
Looking at several Spring Boot/file upload tutorials :
- http://www.mkyong.com/spring-boot/spring-boot-file-upload-example/
- I update avatar image and display it but the avatar does not change in Spring Boot , why?
- Many others
It seems that the standard way of handling such file upload is exposing a controller endpoint that accepts MultipartFiles
like so:
@RestController
@RequestMapping("/v1/profiles")
public class ProfileController {
@PostMapping("/photo")
public ResponseEntity uploadProfilePhoto(@RequestParam("mpf") MultipartFile mpf)
// ...
}
Looking at all this code, I can't tell if the MultipartFile
instance is in-memory or if Spring sets its location somewhere (perhaps under /tmp
?) on the disk.
Looking at the AWS S3 Java SDK tutorial, it seems the standard way to upload a disk-based File is like so:
File file = new File(uploadFileName);
s3client.putObject(new PutObjectRequest(bucketName, keyName, file));
So it looks like I must have a File on disk in order to upload to S3.
I'm wondering if there is a way to keep everything in memory, or whether this is a bad idea and I should stick to disks/File
instances!
- Is there a way to keep the entire profile image (
MultipartFile
) in-mempory inside the controller method? - Is there a way to feed (maybe via serialization?!) a
MultipartFile
instance to S3'sPutObjectRequest
? - Or is this all a terrible idea (if so, why?!)?