Dies ist mein Endpunkt :
Code: Select all
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public List uploadMediaToS3(@RequestPart("files") Set files,
@RequestPart("mediaUploads") Set mediaUploadDTOs,
@RequestParam("profileId") UUID profileId) throws IOException, FindMeDataNotFoundException {
logger.info("WORKED! " + profileId.toString());
return new ArrayList();
}
PS: postMedia ist ein Array von { fileData: fileToSend, base64: event. target!.result!.toString() .
Code: Select all
let formDataWithFiles = new FormData();
let filesRaw = [] as Array;
let filesInfo = [] as Array;
this.postMedias.forEach(postMedia => {
filesRaw.push(new File([postMedia.base64], postMedia.fileData.fileName));
filesInfo.push(postMedia.fileData);
});
formDataWithFiles.append('files', new Blob(filesRaw));
formDataWithFiles.append('mediaUploads', JSON.stringify(filesInfo));
console.log(formDataWithFiles);
this.postService.uploadMedias(formDataWithFiles, this.profileId);
Code: Select all
uploadMedias(files: FormData, profileId: string) {
return firstValueFrom(this.appService.POST(`medias/upload?profileId=${profileId}`, files)).then(savedMedia => {
return savedMedia;
}, error => {
throw error;
});
Meine Dateien werden von einer Eingabetypdatei in meine Angular-Anwendung hochgeladen und mithilfe dieses Codes in einer Variablen gespeichert:
Code: Select all
if (file.target.files[0]['size'] / 1e+6 == this.maxMediaSize) {
this.openSnackBar(this.translateService.instant('CUSTOM-FILE-INPUT.MAX-SIZE-ERROR') + `${this.maxMediaSize}Mb`, 2500);
} else {
let reader = new FileReader();
reader.readAsDataURL(file.target.files[0]);
let fileToSend: Media = {} as Media;
fileToSend.mediaExtension = file.target.files[0].type.substring(file.target.files[0].type.indexOf('/') + 1).toUpperCase();
fileToSend.mediaPrivacy = 'PUBLIC';
fileToSend.mediaPrice = 0.0
fileToSend.whenToDelete = new Date().getTime();
fileToSend.fileName = file.target.files[0].name;
fileToSend.mediaType = 'PROFILE_AVATAR_MEDIA';
reader.onload = (event) => {
this.formFiles.push({ fileData: fileToSend, base64: event.target!.result!.toString() });
};
}
[img]https://i.sstatic. net/BT6FFSzu.png[/img]
Ich habe einen anderen Endpunkt, der eine einzelne Datei speichert und es funktioniert perfekt:
Code: Select all
@PostMapping(value = "/update-avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Media uploadAvatarToS3(@RequestPart("avatar") MultipartFile avatar,
@RequestPart("mediaUpload") MediaUploadDTO mediaUploadDTO,
@RequestParam("profileId") UUID profileId) throws IOException, FindMeDataNotFoundException {
return mediaService.uploadAvatar(avatar, profileId, mediaUploadDTO);
}
Code: Select all
spring.servlet.multipart.enabled=true
spring.servlet.multipart.location=${java.io.tmpdir}
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
Wenn jemand eine Idee hat, was ich ausprobieren könnte, würde es sehr helfen! Vielen Dank im Voraus!