Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Add better file type detection for
/api/upload
. This is done using themagic-bytes
package which has support for browser environment and a tons of file type support.magic-bytes
File
objectfile.type
andfile.name
We need to use a package that support browser api as we are running on edge.
Caveat
Currently we store the filename in our
user_files
table. But in the case that let's say user upload a file of typejpeg
.But the file name is instead
filename.pdf
. In this case we correct the file type but we still store the filename asfilename.pdf
, do you have any suggestion for this?Demo (1.4x speed):
In the demo, I renamed a jpeg screenshot into
.pdf
but the api detected it as jpeg, and use that instead.filetype-detection.mp4