#✅ How to upload a file to a "field" using API?
1 messages · Page 1 of 1 (latest)
Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:
- Adding an explanation of exactly what you're trying to achieve.
- Adding any and all related code or previous attempts.
- Describing the exact issue or error you are facing.
- Posting any screenshots if applicable.
- Reading through https://stackoverflow.com/help/how-to-ask.
When you're done with this thread, please close it. Thanks! ✨
(If you have a support agreement and need help, please contact the core team via email.)
Connected files are a relation to the files collection. You can link them by UUID.
Thanks @craggy condor for the quick reply,
yes I understand that, but it seems I need to pass the ID of that relation and not the UUID of the file, which make sense.
but when I upload the file to the /files endpoint I get only the UUID.
I see there was a new table created relating the files and the collection, do I need to do an api call to that table aswell to create the relation and then update the file field? I would prefer this to be handled all automatically by the backend with a single API call, if possible.
Can I you clarify what you mean?
thanks
When using the singular file field it is an M2O so passing the ID should work. It sounds like you're working with multiple files instead which is a M2M relation requiring you to follow that structure https://docs.directus.io/reference/introduction.html#relational-data
An introduction to the REST and GraphQL APIs in Directus.
ah ok, it makes sense. Tested and worked perfectly.
thanks a lot for the help
✅ How to upload a file to a "field" using API?