Skip to content
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

feat: better file type detection #63

Merged
merged 2 commits into from
Mar 31, 2024
Merged

feat: better file type detection #63

merged 2 commits into from
Mar 31, 2024

Conversation

rin-yato
Copy link
Collaborator

@rin-yato rin-yato commented Mar 30, 2024

Description

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?

image

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

Copy link

vercel bot commented Mar 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
libsql-viewer ⬜️ Ignored (Inspect) Visit Preview Mar 30, 2024 5:03pm

@rin-yato rin-yato changed the base branch from feat/upload-file-to-cell-#51 to develop March 30, 2024 15:51
@rin-yato rin-yato changed the base branch from develop to feat/upload-file-to-cell-#51 March 30, 2024 15:52
@rin-yato
Copy link
Collaborator Author

Pls merge #62 first before merging this

@rin-yato rin-yato requested a review from invisal March 30, 2024 15:53
@rin-yato rin-yato changed the base branch from feat/upload-file-to-cell-#51 to develop March 30, 2024 16:58
@invisal invisal merged commit 936ccc7 into develop Mar 31, 2024
3 checks passed
@invisal invisal deleted the better-filetype branch April 26, 2024 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants