inventory.service.ts I have made some progress in my service file by implementing the functionality to upload a single 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 My inventory form needs to be able to upload an array of images to an S3 bucket and then include the uploaded details in a POST request. Currently, I have only implemented the functionality for uploading a single 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;
});