我正在尝试将文件上传到具有公共访问权限的 AWS S3 存储,但尽管在代码上明确配置了公共访问权限,但文件仍被上传为私有文件。我在Angular 应用程序上使用aws-amplify包。
这是我正在使用的代码:
public onSubmit() {
this.form.disable();
const contentType: string = this.imgFile.extension === 'png' ? 'image/png' : 'image/jpeg';
// Image upload to AWS S3 storage.
Storage.put(this.imgFile.name, this.imgFile.content, {
progressCallback: (progress: any) => {
console.log(`Uploaded: ${progress.loaded}/${progress.total}`);
},
contentType: contentType,
ACL: 'public-read',
visibility: 'public',
level: 'public',
}).then((result: any) => {
this.img = S3_URL + replaceAll(result.key, ' ', '+');
// GraphQL API mutation service.
this.bannerService.createBanner(
this.img,
this.form.value.channel,
this.form.value.trailer,
this.backgroundColor,
this.buttonColor,
this.textColor,
);
// Re-enable the form.
this.form.enable({
onlySelf: true,
emitEvent: true,
});
// Clean all form fields.
this.formElement.nativeElement.reset();
}).catch((err) => {
console.log('error =>', err);
});
}
知道为什么 S3 会忽略我指示的公共访问权限并将文件设为私有吗?提前致谢!