
I am making a reviews section on a website. I am needing to figure out how to like the document (The Review) and the File (The Profile Photo) together so I can call them together? My only idea I got is to get the file name but I am not sure how to extract that

I can just the the id and store it in the doc right

Every file in a bucket has a fileId
and is associated with a bucketId
. You can store these two values in some form of collection/document.

I hope that makes sense

Yes it does. I just noticed that! Feel free to close now

[SOLVED] Linking Storage file and Database Doc

Linking Storage file and Database Doc

@safwan Quick question sorry! What is the best way of grabbing the id from the file when using ID.unique

Not an issue!
I'm assuming you're using ID.unique()
for creating the document.
As for grabbing the file ID, it depends. I grab the IDs whenever a new file is created and store it in the respective document. If you have existing files that you need to link up, I'd suggest manually copy-pasting them lmao

If you have a user interface that let's a user select the photo they want to use, you can use the list files
endpoint to list all the files in a bucket, and then based on the selection, grab the file ID.


storage.createFile('646eb0cc07db82e6dff9', ID.unique(id), profilePhoto.files[0])
console.log(id)
}```

This is what I got

I am needing to know how to grab it the moment its created so I can put it in the respective document

That's perfect. So after storage.createFile
finishes executing, it returns a File Object
. Here's what I would do:
async function PPUpload() {
var newFile = await storage.createFile('646eb0cc07db82e6dff9', ID.unique(id), profilePhoto.files[0])
console.log(newFile.$id)
}

I haven't used js in a while for referring to object keys, and there's a good chance that newFile.$id
may not work lol

Just check and lmk

All works good! Your amazing Thank you for your time!

[SOLVED] Linking Storage file and Database Doc
Recommended threads
- Stuck in "deleting"
my parent element have relationship that doesnt exist and its stuck in "deleting", i cant delete it gives me error: Collection with the requested ID could not b...
- Help with 409 Error on Relationship Setu...
I ran into a 409 document_already_exists issue. with AppWrite so I tried to debug. Here's what I've set up: Collection A has 3 attributes and a two-way 1-to-m...
- 1.7.0 Self Hosted Upgrade
Hi, I've tried a fresh install on 1.7.0 and I've also done a fresh install on 1.6.2. 1.6.2 is working fine fresh, update to 1.7.0 and migrate fails Fresh inst...
