hawaiiose.blogg.se

Resize image client side before upload javascript
Resize image client side before upload javascript








So, this post describes a way to tackle this problem in an efficient way using AWS services. (If you want to read about how images are being uploaded directly to S3 from client, I’ve written about it here) So, doing the conversion on API side was not an option. I was using AWS S3 for storing the pictures, and the pictures were being uploaded to S3 from the client side itself, and the API would just receive the URL for uploaded image. Taking this one step ahead, let’s make two copies of the picture in different sizes - one relatively high res (for profile picture, yearbook picture, etc) and another a bit low res (for displaying on scraps where small size picture is needed) to improve performance. Ideally, what should happen is that once user uploads the picture, it should be resized, compressed and then used. It’s not just the performance, but the cost skyrockets as well, since that large image gets downloaded by so many other users multiple times. Also, if some user uploads a picture in wrong dimensions, it would ruin the UI for other users. If some user uploads a high quality 5 MB picture, the whole application would potentially slow down because of that. One mistake I made and realized a bit late after we got many users, is that I was directly storing the user uploaded profile pictures and then showing them as-is throughout the application.

resize image client side before upload javascript

When a user registers on the platform, they upload an image as their profile picture, which is then used on their profile, as well as on others’ profile if they post a scrap for other users. So, we’re planning to work some more on GradGoggles and reach even more users this time. Since the pandemic hasn’t receded, even the batch of 2021 is going to graduate virtually.

resize image client side before upload javascript

We recieved a very good response from users regarding GradGoggles. You can read the case study for the project here.

resize image client side before upload javascript

Download the image from S3 into a buffer.Last year, I worked on an interesting project which was a virtual yearbook and scrapbook for the graduating batch of 2020 in my college.

resize image client side before upload javascript

Download the image from S3, transform, and upload to a different S3 bucket. dependencies var async = require( 'async') Also, name of .js file is important (we will see that later in this article). You need to download this library and put it in node_modules folder. We would be using async, aws-sdk, gm & path lib.










Resize image client side before upload javascript