ASW-SDK S3上传中载中止
我要中传中载,但是呼叫upload.abort()
提出错误上传中载已上传。
。如何无声地中载上载(没有错误)?
import { PutObjectCommandInput, S3Client } from '@aws-sdk/client-s3';
import { Progress, Upload } from "@aws-sdk/lib-storage";
const uploadParams: PutObjectCommandInput = {
Bucket: 'my-bucket',
Key: 'my-file',
Body: file,
};
const upload: Upload = new Upload({
client: s3Client,
params: uploadParams,
});
// abort after 3 seconds
setTimeout(() => upload.abort(), 3000);
// start upload
upload.done();
我还试图抓住诺言
upload.abort().then().catch(() => {
// ...
})
,也试图尝试抓住一切
try {
upload.abort().then().catch(() => {
// ...
})
} catch () {
// ...
}
I want abort an upload, but calling upload.abort()
raise an error Upload aborted.
. How abort the upload silently (without error)?
import { PutObjectCommandInput, S3Client } from '@aws-sdk/client-s3';
import { Progress, Upload } from "@aws-sdk/lib-storage";
const uploadParams: PutObjectCommandInput = {
Bucket: 'my-bucket',
Key: 'my-file',
Body: file,
};
const upload: Upload = new Upload({
client: s3Client,
params: uploadParams,
});
// abort after 3 seconds
setTimeout(() => upload.abort(), 3000);
// start upload
upload.done();
I have also tried to catch the promise
upload.abort().then().catch(() => {
// ...
})
And also tried to try catch all
try {
upload.abort().then().catch(() => {
// ...
})
} catch () {
// ...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误实际上是从
upload.done
Promise 抛出的。您可以检查代码 这里和此处< /a>
对于您的情况,您需要类似以下内容:
That error is actually being thrown from the
upload.done
Promise.You can check the code here and here
For your case, you would want something like the following: