Tuesday, 3 March 2020

Im trying to make a get request to a very large file hosted on our cloud provider but I'm not exactly sure how

Hey so working on a feature where I would resize an image if its file size was above a certain threshold. As of now, if the image is above 8 mb, i try to resize the image to be smaller. For most cases i've qa'd, a normal get request seems to work. Now, sort of as an experiment/for fun, im trying to pull a 50 mb image from google. My regular request code seems to fail (i'm assuming because of a timeout) so i wrote this but when i log the bugger.byteLength, i get a size of 12017 which cant be right?​`static async _getLargeImageContents ({ imageUrl }) {console.log('image url', imageUrl);return new Promise((resolve, reject) => {let chunks = [];const options = {...Url.parse(imageUrl),timeout: REQUEST_TIMEOUT,};console.log('options', options);let firstPromise = imageUrl.includes('https') ? https : http;const req = firstPromise.get(options, (response) => {response.on('data', (chunk) => {chunks.push(chunk);}).on('end', () => {let buffer = Buffer.concat(chunks);console.log('buffer size', buffer.byteLength);console.log('buffer', buffer);console.log('sizeof', sizeOf(buffer));// console.log('dimensions', dimensions);});});req.on('timeout', () => req.abort());req.on('error', err => reject(err));});}`

Submitted March 03, 2020 at 07:31PM by Prot00ls

No comments:

Post a Comment