我已经尝试了下面的代码,但没有成功,它显示了这个错误消息:
(node:88634) UnhandledPromiseRejectionWarning: NotImplemented: A header you provided implies functionality that is not implementedimport { fromIni } from '@aws-sdk/credential-provider-ini'
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'
import https from 'https'
import { Readable } from 'stream'
import awsConfig from './aws-exports'
const s3Client = new S3Client({
credentials: fromIni({ profile: 'default' }),
region: 'ap-northeast-1',
})
async function getFileFromUrl(url: string): Promise<Readable> {
return new Promise((resolve) => {
https.get(url, (response) => {
resolve(response)
})
})
}
async function upload(file: Readable) {
const uploadCommand = new PutObjectCommand({
Bucket: awsConfig.aws_user_files_s3_bucket,
Key: 'test.jpg',
Body: file,
ACL: 'public-read',
})
await s3Client.send(uploadCommand)
}
async function migrate() {
const file = await getFileFromUrl(
'https://example.com/logo.png'
)
await upload(file)
console.log('done')
}
migrate()我可以确认,如果我将Body更改为字符串...有没有人知道怎么做才是正确的?谢谢!
发布于 2021-07-25 22:13:32
这里的问题是你的getFileFromUrl函数不工作,并且亚马逊网络服务不知道如何处理你正在处理的对象。您需要等待来自https的数据事件,如下所示:
async function getFileFromUrl (url) {
return new Promise((resolve) => {
https.get(url, (response) => {
response.on('data', (d) => {
resolve(d)
})
})
})
}https://stackoverflow.com/questions/67228636
复制相似问题