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

30 messages · Page 1 of 1 (latest)

floral flicker
#

I'm creating a kind of note keeper where a user can upload a thumbnail cover related to their notes. This is my DB structure. Everything is working fine and things are getting rendered when I'm trying to list documents.

But when a user is trying to upload an image, it's not taking and also I don't know how to do that using storage() inside a form.

opal rapids
#

you need to use bucket for that (or image base64 but it's not recommended)

floral flicker
opal rapids
#

Really depends of your workflow.. Imagine, when a user create an account, you create a bucket for him, with permission. Like that he can upload image on bucket, and you image field contain a reference to

#

Possible workflow, without function

  1. Upload file on bucket & get id of file
  2. Submit form with this reference
floral flicker
#

Let me try

strange moth
#

Hi @floral flicker , let us know if it doesn't

umbral karma
#

@opal rapids'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.
floral flicker
#

But there's another issue now.

#

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

umbral karma
floral flicker
umbral karma
#

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.

#

You can try resizing them on the client-side

floral flicker
umbral karma
#

What platform are you building on?

floral flicker
#

Next.js, Tailwind

umbral karma
#

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

floral flicker
#

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

umbral karma
#

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

#

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

umbral karma
#

should work

floral flicker
umbral karma
floral flicker
#

Solved

#

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