【发布时间】:2021-09-07 11:36:10
【问题描述】:
我正在尝试使用 apollo-upload-client 库通过 graphql 将图像上传到 S3,该库仅提供通过 graphql 查询发送图像的能力。
因此,图像在 S3 存储桶中进行了叙述,但是当我尝试读取 Location url 时,它似乎不起作用。当我阅读带有<img src="img_url" /> 的网址时,它只会显示:
当我尝试手动输入链接时,它只是自动下载一个带有很多奇怪符号的奇怪文本文件。
这就是upload 的样子:
export async function uploadImageResolver(
_parent,
{ file }: MutationUploadImageArgs,
context: Context,
): Promise<string> {
// identify(context);
const { createReadStream, filename, mimetype } = await file;
const response = await s3
.upload({
ACL: 'public-read',
Bucket: environment.bucketName,
Body: createReadStream(),
Key: uuid(),
ContentType: mimetype,
})
.promise();
return response.Location;
}
File 对象的示例如下所示:
{
filename: 'Screenshot 2021-06-15 at 13.18.10.png',
mimetype: 'image/png',
encoding: '7bit',
createReadStream: [Function: createReadStream]
}
我做错了什么?它返回一个实际的 S3 链接,但链接本身不显示任何图像。我尝试手动将相同的图像上传到 S3,它工作得很好。提前感谢您的任何建议!
【问题讨论】:
-
上传问题已经解决...使用搜索?
-
在发布这个问题之前,我已经搜索了帖子、教程和文档。有一点关于这个
graphql-upload-client的信息。此外,所有教程都在执行相同的步骤。我的问题是我找不到问题,我真的不知道为什么不起作用。 -
为什么是客户端问题?看起来像一个常见的服务器/API/解析器/节点问题...响应在处理之前返回/关闭...
await s3.upload...? -
我在
s3.upload..之前调用await我只是没有将它粘贴到示例中抱歉。我将编辑示例代码。 -
没什么大的变化......有很多
corrupt s3 upload问题要挖掘......s3 forward upload(以及相关的'multipart','chunks'),pipe stream,没有缓冲(节省中间存储空间)等..只需搜索更好的示例/答案
标签: amazon-web-services amazon-s3 graphql serverless serverless-offline