【发布时间】:2021-08-10 02:32:51
【问题描述】:
我正在尝试将 zip 文件上传到 Azure 文件共享。 zip 文件是使用archiver 库生成的,我尝试使用管道上传它。我总是收到错误StorageError: The range specified is invalid for the current size of the resource.。如何找出我的档案的大小?我尝试像这样“收集”拉链的大小:
const uploadStream = new stream.PassThrough();
zip.pipe(uploadStream);
zip.finalize();
zip.on("data", (chunk) => {
this.zipSize += chunk.length;
});
zip.on("finish", () => {
console.log(this.zipSize);
this._callFileService(uploadStream);
});
async _callFileService(data: stream.PassThrough) {
fileService.createShareIfNotExists(
this.name,
(error, result, response) => {
if (!error) {
fileService.createFileFromStream(
this.name,
"",
"test.zip",
data,
this.zipSize,
{},
function (error, result, response) {
if (error) {
console.log(error);
} else {
console.log("Done upload");
console.log(result, response);
}
},
);
} else {
console.log("there was an error: ", error);
}
},
);
}
我也尝试仅获取存档的大小,并尝试使用stream.writableLength,但一切都会引发相同的错误。帮忙?
【问题讨论】:
标签: javascript node.js azure stream