I have the issue that some files, for example many videos seemingly cannot be properly uploaded with base64 encoding, but with React Native the update function of supabase only works with base64 encoding, i can’t upload them. Is there any workaround i haven’t seen yet? Any help is appreciated!
This is my code:
const base64 = await FileSystem.readAsStringAsync(uri, {
encoding: FileSystem.EncodingType.Base64,
});
const { error } = await supabase.storage
.from("files")
.upload(filePath, decode(base64), {
contentType: mimeType,
});
The error i get: "TypeError: Network request failed"
Documentation of supabase: https://supabase.com/docs/reference/javascript/storage-from-upload?example=upload-file-using-arraybuffer-from-base64-file-data
Supabase documentation. Upload only possible with base64 encoding?
I tried using a different encoding function, upload with blob and just directly giving the function the file returned by the DocumentPicker. Looked up if any other variables are incorrect, but everything else works as it should. Images and even one specific video are being uploaded correctly.
The DocumentPicker (from expo):
result = await DocumentPicker.getDocumentAsync({
type: "*/*", // Allow all file types
copyToCacheDirectory: true,
});
I really don’t know how i could fix this. Please help!
2
Answers
Did you see in the Supabase documentation that they recommend that you use TUS Resumable Uploads for any file larger than 5MB? (remember: base64 encoding will greatly increase the size of your data)
Despite the specification says
FormData
does not work as intended, this works. Hereuri
is fromImagePicker
.