0

我从 Busboy 获取文件流,然后我需要计算字节数,抓取第一行,然后将其发送到 azure 存储。它适用于最大约 25MB 的文件,但之后不计算所有字节。我不知道如何让它等待。我使用直通流只是为了在获得第一行时保存原始数据。

busboy
.on('file', function(fieldname, file, filename, encoding, mimetype) {
    file
    .on('data', function(data) {
        bytes = bytes + data.length;
    })
    .on('end', function() {
        console.log("end");
    })
    .pipe(passthrough)
    .pipe(firstLine)
    .pipe(es.wait(function (err, body) {
        blobService.createBlockBlobFromStream(containter, name, passthrough, bytes, function (error, result) {
            if(error) {
                return sendResponse(error.toString(), res, null);
            }
            sendResponse(null, res, "done");
        });
    }));
})
.on('finish', function() {
    console.log("busboy done");
});
4

1 回答 1

0

如果要将数据通过管道传输到 blob,createWriteStreamToBlockBlob 是您可能需要的 API。

busboy
.on('file', function(fieldname, file, filename, encoding, mimetype) {
  file
  .on('data', function(data) {
    bytes = bytes + data.length;
  })
  .on('end', function() {
    console.log("end");
  })
  .pipe(passthrough)
  .pipe(firstLine)
  .pipe(blobService.createWriteStreamToBlockBlob(containter, name, function (error, result) {
     if(error) {
        return sendResponse(error.toString(), res, null);
     }
     sendResponse(null, res, "done");
  }))
})
.on('finish', function() {
  console.log("busboy done");
});
于 2015-10-20T05:48:41.240 回答