node.js - 未捕获的错误:超过了 2097152 字节的 DelayedStream#maxDataSize
问题描述
我想将文件上传到 s3 但不等待它但是我收到以下错误。
未捕获的错误:超过了 2097152 字节的 DelayedStream#maxDataSize。在 FormData.CombinedStream._checkDataSize (node_modules/combined-stream/lib/combined_stream.js:166:19) 在 Readable.EventEmitter.emit (domain.js:476:20) 在 Readable.source.emit (node_modules/delayed-stream /lib/delayed_stream.js:30:21) 在 Readable.read (_stream_readable.js:520:10) 在 ManagedUpload.fillStream (node_modules/aws-sdk/lib/s3/managed_upload.js:422:25) 在 Readable。(node_modules/aws-sdk/lib/s3/managed_upload.js:188:44) 在 Readable.EventEmitter.emit (domain.js:476:20) 在 Readable.source.emit (node_modules/delayed-stream/lib/delayed_stream .js:30:21) 在emitReadable_ (_stream_readable.js:570:12) 在 processTicksAndRejections (internal/process/task_queues.js:77:11)
用法:
console.log(image)
this.storageModule.upload(`${requestId}-${type}.jpg`, image)
> Readable {
> _readableState: ReadableState {
> objectMode: false,
> highWaterMark: 16384,
> buffer: BufferList { head: null, tail: null, length: 0 },
> length: 0,
> pipes: null,
> pipesCount: 0,
> flowing: null,
> ended: false,
> endEmitted: false,
> reading: false,
> sync: true,
> needReadable: false,
> emittedReadable: false,
> readableListening: false,
> resumeScheduled: false,
> paused: true,
> emitClose: true,
> autoDestroy: false,
> destroyed: false,
> defaultEncoding: 'utf8',
> awaitDrain: 0,
> readingMore: false,
> decoder: null,
> encoding: null
> },
> readable: true,
> _read: [Function: read],
> _events: [Object: null prototype] {},
> _eventsCount: 0,
> _maxListeners: undefined
> }
存储模块
import Config from "../../config/config";
import S3 from "aws-sdk/clients/s3";
class StorageModule {
public config: Config;
public s3: S3;
public bucket: string;
constructor() {
this.config = new Config();
const credentials: S3.ClientConfiguration = {
accessKeyId: this.config.aws.AWS_S3_ACCESS_KEY_ID,
secretAccessKey: this.config.aws.AWS_S3_SECRET_ACCESS_KEY,
region: this.config.aws.AWS_S3_REGION,
};
this.s3 = new S3(credentials);
this.bucket = "test-bucket-name";
}
}
public upload = (key, body) => {
const params = {
Bucket: this.bucket,
Key: key,
Body: body
}
return this.s3.upload(params).promise()
}
}
export default StorageModule;
但是,当我从测试运行上传时,它可以工作。
import StorageModule from "./storage.module";
import fs from "fs";
import { expect } from "chai";
describe("StorageModule", () => {
it("should upload file to s3", async () => {
const storageModule = new StorageModule();
const stream = await fs.createReadStream(process.cwd() + "/test/resources/" + "id/front.jpg");
console.log(stream);
const key = "test/productId/sessionId/requestId-front.jpg"
const response = await storageModule.upload(key, stream);
expect(response.Location).to.equal(`${base}/${key}`)
});
});
它与可读流有关吗,因为我尝试上传的图像完全相同?
解决方案
推荐阅读
- c - C程序只写?到新文件
- asp.net-mvc - 在不注销并重新登录的情况下更新索赔值
- apache-spark - 如何在火花中将数据框转换为文本文件?
- kubernetes - 更新挂载的秘密时自动刷新 POD,但看起来没有发生
- python - 下面给出的“俄罗斯方块”游戏问题中的问题是什么?
- javascript - 如何使用jquery选择动态id
- c# - NAudio 的 BufferedWaveProvider 在录制和混合音频时变满
- angular - 我无法在 ionic 3 中查看谷歌地图?
- databricks - Databricks:在 cron 上删除根 DBFS 上的集群日志和修订
- kubernetes - Why is EMQX Persistence not working on azure kubernetes when it is working on local kubernetes?