当出现此问题时,可以遵循以下步骤进行解决:
确认您的 S3 存储桶中是否存在要求的图像。您可以在 Amazon S3 控制台中使用相应的存储桶名称来查看存储桶中的图像。
确认您在 Amplify 应用程序中设置了正确的 S3 存储桶名称和对象键。您可以查看您的应用程序配置文件中的 amplify/storage 字段。
如果您正在使用 Amplify Storage SDK 进行图像的上传或访问,请使用相应的方法参数提供正确的 S3 存储桶名称和对象键。
以下是使用 Amplify Storage SDK 进行图像上传的示例代码(假设您已经在您的应用程序中正确配置了 Amplify Storage):
import { Storage } from 'aws-amplify';
// 上传图片
Storage.put('example.jpg', fileObj)
.then(result => console.log('上传成功:', result))
.catch(err => console.log('上传失败:', err));
// 获取图片 URL
Storage.get('example.jpg', { expires: 300 })
.then(result => console.log('获取成功:', result))
.catch(err => console.log('获取失败:', err));
请注意,在上述示例代码中,'example.jpg' 表示您要上传或获取的图像的对象键。如果出现 404 Not Found 错误,请检查该键是否正确,并检查存储桶中是否存在该图像。