Stream raw file to upload (supabase-fetcher) #53
Merged
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.
Problem
The
Supabase.Fetcher.upload/4
function currently usesFile.stream!/3
withencoding: :utf8
to read file contents during uploads. This causes issues when uploading non-UTF-8 files, such as binary files (e.g., MP3s), resulting in:invalid_unicode
errors. Users have reported difficulties uploading files to Supabase Storage due to this limitation.Additionally, the implementation does not dynamically determine the
Content-Type
header based on the file being uploaded, which can lead to incorrect file handling on the server.References
Solution
Refactor the
Supabase.Fetcher.upload/4
function to address the following:Remove UTF-8 Encoding:
File.stream!/3
to use the:raw
option instead of:utf8
, which ensures that binary files can be read without errors.Determine MIME Type:
mime
to detect the file's MIME type dynamically.Set the Correct
Content-Type
Header:Rationale
:utf8
encoding resolves errors when streaming binary files (e.g., MP3s, images).:raw
option reads files as-is without attempting to interpret their content as a specific character set.