Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
1. Update Jimp version; 2. Convert callback to async/await syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
BaiYinSilver committed Jun 23, 2020
1 parent 53a4202 commit c3268b6
Show file tree
Hide file tree
Showing 3 changed files with 434 additions and 418 deletions.
45 changes: 17 additions & 28 deletions Thumbnail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,26 @@ module.exports = (context, eventGridEvent, inputBlob) => {
const blobUrl = context.bindingData.data.url;
const blobName = blobUrl.slice(blobUrl.lastIndexOf("/")+1);

Jimp.read(inputBlob).then( (thumbnail) => {
const image = await Jimp.read(inputBlob);
const thumbnail = image.resize(widthInPixels, Jimp.AUTO);
const thumbnailBuffer = await thumbnail.getBufferAsync(Jimp.AUTO);
const readStream = stream.PassThrough();
readStream.end(thumbnailBuffer);
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName);
try {

thumbnail.resize(widthInPixels, Jimp.AUTO);
await uploadStreamToBlockBlob(aborter, readStream,
blockBlobURL, uploadOptions.bufferSize, uploadOptions.maxBuffers,
{ blobHTTPHeaders: { blobContentType: "image/jpeg" } });

const options = {
contentSettings: { contentType: contentType }
};
} catch (err) {

thumbnail.getBuffer(Jimp.MIME_PNG, async (err, buffer) => {
context.log(err.message);

const readStream = stream.PassThrough();
readStream.end(buffer);
} finally {

const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName);
context.done();

try {

await uploadStreamToBlockBlob(aborter, readStream,
blockBlobURL, uploadOptions.bufferSize, uploadOptions.maxBuffers,
{ blobHTTPHeaders: { blobContentType: "image/jpeg" } });

} catch (err) {

context.log(err.message);

} finally {

context.done();

}
});
});
};
}
};
Loading

0 comments on commit c3268b6

Please sign in to comment.