Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Firebase Initial Uploaded Image results in "Client uploaded to the wrong offset (262144 instead of 0)" #180

Closed
kenmaca opened this issue Nov 14, 2016 · 7 comments

Comments

@kenmaca
Copy link

kenmaca commented Nov 14, 2016

Following the example here: https://github.com/wkh237/rn-firebase-storage-upload-sample/blob/master/index.common.js

                 Blob.build(
                  RNFetchBlob.wrap(
                    this.props.path
                  ), {
                    type: 'image/jpg;'
                  }
                ).then(blob => {
                  let task = Firebase.storage().ref().child(
                    `images/${
                      this.props.path.split('/').pop()
                    }`
                  ).put(blob, {
                    contentType: 'image/jpg'
                  });

...

on React Native 0.36.0 and Firebase results in a Client uploaded to the wrong offset (262144 instead of 0) error returned from Firebase.

This only happens for a larger image on an app that has never uploaded anything successfully before. If I try to upload a photo of a solid colour (that I assume has a smaller file size), it works and allows all subsequent uploads (regardless of size) to work as well.

The same code was working without these issues two weeks ago.

Also, some other people are having the same issue: https://groups.google.com/forum/#!msg/firebase-talk/ejc4hbwUNy4/A4JvNCvIBwAJ

@wkh237
Copy link
Owner

wkh237 commented Nov 15, 2016

@kenmaca , thanks for the great information, I'll look into it once I have time 👍

@wkh237
Copy link
Owner

wkh237 commented Nov 15, 2016

Besides, if you're interested in tracing the log you may turn on the logs (there will be a tons). By uncomment these lines :

Turn on XMLHttpRequest logs :

https://github.com/wkh237/react-native-fetch-blob/blob/master/src/polyfill/XMLHttpRequest.js#L15

Turn on Blob polyfill logs

https://github.com/wkh237/react-native-fetch-blob/blob/master/src/polyfill/Blob.js#L15

@wkh237
Copy link
Owner

wkh237 commented Nov 23, 2016

@kenmaca , there has been a fix launched in 0.10.1-beta.1, please try use this version and see if it works, thank you.

@kenmaca
Copy link
Author

kenmaca commented Nov 24, 2016

Thanks @wkh237 for the follow up!

Unfortunately, that didn't fix my issue. But, I was able to apply a quick fix on my end that got everything working (which may help you fix this bug with the Blob polyfill). Basically adding Blob.clearCache() and then the upload code after that resolves fixed this issue for me.

So, I have a feeling that the reason why smaller files work is because slice isn't called -- and slicing places temporary files into RNFetchBlob-blobs, which doesn't exist initially. After the first successful upload (or in my fix, clearCache), the folder is created and future uploads start working again. I guess a simple stat to check if the folder exists (and create it if it doesn't) before any blobs are saved will close this issue.

Hope this helps! (And thank you so much for this amazing module)

@wkh237
Copy link
Owner

wkh237 commented Nov 24, 2016

@kenmaca , thanks so much for the detailed information 👍 I'll look into this issue and find an appropriate way to fix it. Will update there once I have any progress 😄

@wkh237
Copy link
Owner

wkh237 commented Nov 24, 2016

@kenmaca , I've added a check mechanism to Blob.slice to ensure the cache folder exists. This fix has been launched in 0.10.1-beta.2, could you try if that fixes the issue ? 😅

@wcandillon
Copy link

@kenmaca reading the e-mail thread at https://groups.google.com/forum/?fromgroups#!topic/firebase-talk/ejc4hbwUNy4 solved the issue for me.

@wkh237 wkh237 closed this as completed Jan 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants