inventory.service.ts This is what i have implemented so far in my service file. It was just to upload one image file.
public uploadImage(file: File, fileName): Promise<ManagedUpload.SendData> {
const contentType = file.type;
const params = {
Bucket: environment.bucketName,
Key: fileName,
Body: file,
ACL: "public-read",
ContentType: contentType
};
return this.bucket.upload(params, (err, data) => {
return !err;
}).promise();
}
inventoryForm.ts In my inventory form i want to upload an array of images to S3 bucket and get that uploaded details and append to my POST request. This is what i have implemente to upload just one image
this.imageService.uploadImage((this.imageFile?.item(0)), fileName)
.then((data) => {
this.toastrService.showSuccessToastr("Image was successfully added");
this.inventoryImage = {
url: data.Location,
key: data.Key
};
this.submitRequest();
}).catch((error) => {
this.toastrService.showErrorToastr("Error occurred while uploading image ");
this.loading = false;
});