【发布时间】:2020-11-12 09:16:01
【问题描述】:
目前我可以通过在本地保存文件来将文件上传到 Blob 存储。但我想将文件直接流式传输到存储。因为我对文件系统完全陌生,所以我无法使用 createReadStrem(filepath) 来做到这一点,因为它需要文件路径,并且在搜索时我看到它不可能从前端获取路径。我将文件分成块并写入流。如果有人可以帮助我以任何方式做到这一点?
Headers:
X-Chunk-Id: 0
X-Content-Id: a997d61859d6d3814d5f3f4a..
x-Content-Length: 19
payload:
fdfdfgytuujftyeeyjh // hi.txt dummyfiledata it can be zip file also
API
const fs = require("fs");
function uploadToBlob(request, response) {
const chunkComplete = file.pushChunk(chunkId, chunk, chunkSize);
const size = file.getChunkLength(chunkId);
if (file.isCompleted()) {
var userrole = file.userrole;
var projectId = file.id;
var projectname = file.path;
var fileName = file.name;
var blobName = projectname + '/' + file.name;
var sourceFilePath = __dirname + '/uploads/' + file.name;
const fstream = fs.createReadStrem(sourceFilePath);
let chunks = file.getContent();
for (let j = 0; j < chunks.length; j++)
{
fstream.write(chunks[j]);
}
fstream.end();
delete fileStorage[fileId];
fstream.on("finish", () => {
// bs.createBlockBlobFromLocalfile( file gets saved to blob storage)
//Instead i want to use bs.createBlockBlobFromstream() here and stream directly to blob without saving locally
}
}
}
【问题讨论】:
标签: node.js azure azure-blob-storage