-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Content-Type header check in Files POST requests #16176
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to document the option of sending JSON to the /files
endpoint? The current docs explicitly say you need to use multipart/form-data
(https://docs.directus.io/reference/files.html#upload-a-file).
I think we should make type
a required property when creating an empty file. The current test payload { title: 'Test File', storage: 'local', filename_download: 'test_file' }
gets a success response and is saved to the database but is not rendered in the App.
firefox_p2glGt8dGa.mp4
Agreed 👍
That's a great point. Though I do wonder if it's intentional (and there's an existing assumption) that file type may be null? 🤔 It seems to be filtered here: directus/app/src/modules/files/routes/collection.vue Lines 259 to 263 in a664623
FWIW I do personally still wonder what is/was the utility of being able to make the POST request without a file. @rijkvanzanten thoughts on these points/questions? Here's a quick summary:
|
The only real use case is so you can associate metadata with a file that already exists on disk |
That does makes sense! In that case, I assume
@br41nslug upon further inspection, I've noticed this block of code setting the default type for uploaded files in case there's no type: directus/api/src/services/files.ts Lines 68 to 70 in 2adbb3b
Perhaps we can do the same for JSON payload? It does at least show up in the App after I tested to put such default in place. |
We definitely could but as Rijk said the usecase for this is to associate meta with already existing files i think requiring people to assign the correct type for that may be the better way to go. |
Makes sense! Was partially wondering would it be too strict in the case where the user themselves aren't sure about the type, but it does feel like that should fall under the responsibility of users going with such use case to be begin with. Added a check for "type" in FileService's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good 😄
Description
Fixes #16140
#11347 moved the content type header check from
multipartHandler
to the files POST request controller, however it was wrongly assumed that POST request must always include multipart file(s). This prevented the creation of file entry without actual file which was supported prior to that PR. Hence this PR removes the check altogether.Type of Change
Requirements Checklist
If adding a new feature: