所以我使用 lambda 函数来执行此操作,但由于某种原因图像没有显示,我如何显示 s3 中的图像?这是一个示例链接:https://beconnectedtest-apex-home-kdanibeconnectedbucket11-7dpaorylr8fc.s3.eu-central-1.amazonaws.com/U065SLKNC2Y/1701873226742
这是我的功能:
// Upload the post to the daily private channel.
const file = `https://${bucketName}.s3.eu-central-1.amazonaws.com/${metaData.userid}/${metaData.timestamp}`
console.log(`File path: ${file}`)
await app.client.chat.postMessage({
channel: dailyChannel.channels.find(
(channel: any) => channel.name === dailyChannelName
).id,
attachments: [
{
fallback: 'Uploaded a new picture',
title: 'from BeConnected',
text: `<@${metaData.userid}> Uploaded a new picture + https://${bucketName}.s3.eu-central-1.amazonaws.com/${metaData.userid}/${metaData.timestamp}`,
image_url: `https://${bucketName}.s3.eu-central-1.amazonaws.com/${metaData.userid}/${metaData.timestamp}`,
},
],
})
} }
我希望图像显示在消息中,就像我直接从电脑发送图像一样。
//编辑 这是我将图像上传到 s3 的位置和方式,也许这就是我真正不知道的问题所在。我大约几周才开始使用 slack 和 aws
// Upload the image to S3
const response = await fetch(uploadUrl, {
method: 'PUT',
body: mergedImage,
headers: {
'Content-Type': 'image/png', // Specify the correct header for content type
},
})
好吧,问题是我将图像上传为base64文本,因为我使用canvas.toDataUrl而不是canvas.toBlob,我更改了它,最后它工作正常!