Back

[SOLVED] How to store image inside Appwrite bucket given by user in the file upload input field

  • 0
  • Databases
  • Web
  • Storage
Bouahaza
29 May, 2023, 16:27

Possible workflow, without function

  1. Upload file on bucket & get id of file
  2. Submit form with this reference
TL;DR
User had a doubt about how to store images in an Appwrite bucket given by the user in a file upload input field. They asked for a GitHub repo or code snippets for reference. Another user suggested wrapping the `<img>` tag with a `div` of the desired size and making the `<img>` fill up the `div`. The user mentioned using `next/image` but it was giving errors, so they switched to using the `<img>` tag. They also mentioned that when previewing the images, they are of different sizes and asked for a solution to fix that. Another user suggested resizing the images on the client-side. The
Susmita
29 May, 2023, 16:28

Let me try

joeyouss
30 May, 2023, 07:04

Hi @Susmita , let us know if it doesn't

safwan
30 May, 2023, 08:24

@Bouahaza's suggestion is perfect in my opinion.

Something I do, which is a tiny bit different from the suggestion is this:

  • Have a bucket for all images
  • Have an attribute in a collection for storing the appropriate file ID.
  • When a user wants to upload an image that's only accessible by them, I execute a cloud function that takes the image and userID as an input. I then create a file in the bucket with permissions for that user only, and store the fileId in the document as needed.
Susmita
31 May, 2023, 12:04

It worked!!

Susmita
31 May, 2023, 12:05

But there's another issue now.

Susmita
31 May, 2023, 12:06

When images are previewed, they are of different sizes due to which UI is not looking good. How to fix that?

safwan
31 May, 2023, 12:08

Are all the stored images the same size?

Susmita
31 May, 2023, 12:08

No

safwan
31 May, 2023, 12:09

If they are, then this is weird. But if they're not the same size, then that's the intended way for this to work.

safwan
31 May, 2023, 12:09

You can try resizing them on the client-side

Susmita
31 May, 2023, 12:10

Yeah, I tried but the problem is with the images which are small in size are even getting smaller and the bigger ones are getting to the perfect size of the card

safwan
31 May, 2023, 12:10

What platform are you building on?

Susmita
31 May, 2023, 12:10

Next.js, Tailwind

safwan
31 May, 2023, 12:11

Are you using next/image or the <img> tage?

Susmita
31 May, 2023, 12:12

next/image was giving some errors, so I'm using <img> tag

safwan
31 May, 2023, 12:12

next/image has two props width and height that take in logical pixels. So if you pass in 100 for both of them, all images should be 100x100. If not perfect 100x100, they'll be close to it

safwan
31 May, 2023, 12:12

Cuz i think next/image maintains the aspect ratio. not sure.

safwan
31 May, 2023, 12:14

okay the <img> definitely is more flexible. Wrap the <img> with a div of your chosen size. Then make the <img> fill up the div

safwan
31 May, 2023, 12:14

should work

Susmita
31 May, 2023, 12:14

let me try

safwan
31 May, 2023, 12:14

sure

Susmita
1 Jun, 2023, 03:51

Solved

Susmita
1 Jun, 2023, 03:51

[SOLVED] How to store image inside Appwrite bucket given by user in the file upload input field

Jaydeep
5 Jun, 2023, 04:19

i had the same doubt regarding image upload. If you don't can you share any github repo to understand as an example. Or any code snippets. Thanks 😃

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more