Add better file type detection for /api/upload. This is done using the magic-bytes package which has support for browser environment and a tons of file type support.
try to detect file type information using magic-bytes
fallback to the File object file.type and file.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 type jpeg.
But the file name is instead filename.pdf. In this case we correct the file type but we still store the filename as filename.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.
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 insteadfilename.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.https://github.com/invisal/libsql-studio/assets/106462074/57cf68e8-a645-4e89-83ed-c22a7aeca72a