Skip to content

Commit

Permalink
Merge pull request #50 from hahabsw/add-upload-stream
Browse files Browse the repository at this point in the history
Add uploadStream method.
  • Loading branch information
jakeFeldman authored Jun 22, 2022
2 parents e6406e1 + 64477db commit 5822d68
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ module.exports = {
}
).then(resolve, reject);
}),
uploadStream: file => new Promise((resolve, reject) => {
const fileName = file.hash + file.ext;
const containerWithPath = Object.assign({}, containerURL);
containerWithPath.url += file.path ? `/${file.path}` : `/${config.defaultPath}`;

const blobURL = BlobURL.fromContainerURL(containerWithPath, fileName);
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);

file.url = cdnBaseURL
? blobURL.url.replace(serviceBaseURL, cdnBaseURL)
: blobURL.url;

return uploadStreamToBlockBlob(
Aborter.timeout(60 * 60 * 1000),
file.stream, blockBlobURL,
4 * 1024 * 1024,
~~(config.maxConcurent) || 20,
{
blobHTTPHeaders: {
blobContentType: file.mime
}
}
).then(resolve, reject);
}),
delete: file => new Promise((resolve, reject) => {
let fileUrl = file.url;
if (cdnBaseURL) {
Expand Down

0 comments on commit 5822d68

Please sign in to comment.