-
Notifications
You must be signed in to change notification settings - Fork 126
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
How to create a Blob? #297
Comments
What do you want to do? |
I'm trying to upload a .m4a file from a react-native app using Expo to an upload endpoint in another app (a Rails app with a Shrine upload endpoint to be precise). The upload endpoint seems to work well, as confirmed by posting with POSTMAN, and in a node.js script, but from React native, nothing works so far, and my best guess at the moment is this lack of support for Blobs, that's how I found this module. Here's what I'm trying: const fPath = FILE_PATH_RECORDINGS + audioFileEntry.name;
const fWrapped = ReactNativeBlobUtil.wrap(fPath.replace('file://', ''));
// "ReactNativeBlobUtil-file:///Users/...../Documents/recordings/Audio_09-20_19_30_15.m4a"
ReactNativeBlobUtil.fetch(
'POST',
apiUrl,
{
// Authorization: "Bearer access-token",
// Tried both content types
'Content-Type': 'application/octet-stream',
// 'Content-Type': 'multipart/form-data',
},
fWrapped,
// Tried with a complete object as well, with and without the array
// [
// {
// name: audioFileEntry.name,
// filename: audioFileEntry.name,
// type: 'audio/x-m4a',
// data: fWrapped
// },
// ]
)
.then((res) => {
console.log('response.text: ' + res.text())
})
.catch((err) => {
console.error(err);
console.error('Audio file upload failed.');
}) Creating the Happy to provide any other details. |
To be honest, depending on how your endpoint looks you don't need this lib at all. For uploading files I usually use formdata. But your api of course most fit to that.
|
@RonRadtke Omg, this worked! I've been trying to figure this out for days and thought I already had tried this before, but apparently not. Do you know if there's a file size limit for this approach? I expect the biggest audios to be around 50-100MB Thank you so much! |
@brunops I'm glad it worked! In general there is no limit you should have an problems with on the app side. |
Hi @brunops, could you show me what your server/endpoint looks like ? I'm trying the same thing as you but the request body is always empty :( |
Hey @perroudsky! It's a rails app in this case, so it only uses |
Hello, sorry if this is a dumb question, but how do I create a simple
Blob
object after installing this module?I can't figure this out at all from reading the README, docs, and the code of the module itself. I saw there's a
Blob
polyfill inside it, but neither the constructor nor the.build
method are available:Is this supposed to be a private api?
Thanks
The text was updated successfully, but these errors were encountered: