Skip to content

[docs][storage] missing documentation #170

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

Closed
Salakar opened this issue Jun 15, 2017 · 10 comments
Closed

[docs][storage] missing documentation #170

Salakar opened this issue Jun 15, 2017 · 10 comments
Assignees
Labels
plugin: storage Firebase Cloud Storage
Milestone

Comments

@Salakar
Copy link
Contributor

Salakar commented Jun 15, 2017

Storage docs are a bit empty and there are several undocumented methods.

Could do with adding those and also expanding on the full upload/download process from start to finish, documenting the provided statics and documenting the metadata object returned from putFile / downloadFile.

@Salakar Salakar added docs plugin: storage Firebase Cloud Storage labels Jun 15, 2017
@Salakar Salakar added this to the v2.x milestone Jun 15, 2017
@Ehesp
Copy link
Member

Ehesp commented Jun 15, 2017

Was the issue around multiple responses sorted? You know the web SDK could do promises, callbacks etc?

@Salakar
Copy link
Contributor Author

Salakar commented Jun 15, 2017

@Ehesp believe so - also made this issue based on feed back from discord

@fungilation
Copy link
Contributor

fungilation commented Jul 19, 2017

@Salakar, I don't know if this is a documentation issue or something else with the Storage api. But I'm at a loss in making Storage work with putFile(). My sample code:

import RNFS from 'react-native-fs'

import RNFirebase from 'react-native-firebase'
const firebase = RNFirebase.initializeApp({ debug: false, persistence: true })
firebase.database().goOnline()
firebase.auth().signInAnonymously()

      // create a path you want to write to. contentHash is a sha3 hash of result.content
      var path = `${RNFS.DocumentDirectoryPath}/${contentHash}.json`

      // write the file. result is an object
      RNFS.writeFile(path, JSON.stringify(result), 'utf8')
        .then((success) => {
          console.log('FILE WRITTEN at ', path)
        })
        .catch((err) => {
          console.log('Write error:', err.message, err.code)
        })

      firebase.storage()
        .ref('/resultJsonByContentHash/' + contentHash)
        .putFile(path)
        .then(uploadedFile => {
          console.log('Uploaded to firebase:', uploadedFile)
        })
        .catch(err => {
          console.log('Firebase putFile error:', err)
        })

      RNFS.unlink(path)

Chrome console output from firebase.storage() would always fail, with

Firebase putFile error: Error: An unknown error has occurred.
    at createErrorFromErrorData (NativeModules.js:121)
    at NativeModules.js:78
    at MessageQueue.__invokeCallback (MessageQueue.js:301)
    at MessageQueue.js:118
    at MessageQueue.__guard (MessageQueue.js:228)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:117)
    at debuggerWorker.js:71

Looking at my Firebase console, I would see files created at the correct path, but with all files with this as content: (instead of the serialized json first written to local file)

{"contentType":"application\/octet-stream","name":"resultJsonByContentHash\/eada2f3ab7072495fd96bdfd69345ebd9a1c5caa24986fce35043f935d6791a3"}

Am I missing something?

@chrisbianca
Copy link
Contributor

@fungilation This does seem strange. There should be an error in the native console for the part of the native code that corresponds to the JS error you've included above. Are you able to take a look and attach that so we have something to work with?

Also, are you 100% sure that the file is written correctly by RNFS and it isn't actually writing the content that's being uploaded? Perhaps use RNFS to read the file you've created and check that it is what you'd expect?

I'm only using storage().putFile() for images so this is the only use case that I've had to test is working correctly. I think for the most part this has been the case for all users with storage so far.

@fungilation
Copy link
Contributor

Thanks for the quick response!

What do you mean by native console. In xcode attached to running app?

Yes I'm 100% sure the local file is written correctly with serialised json. I haven't pasted more of my code which read out the file on the same path.

@chrisbianca
Copy link
Contributor

Yep, Xcode should have some logs corresponding to the error being reported on the JS side

@fungilation
Copy link
Contributor

fungilation commented Jul 19, 2017

Here's a chunk of xcode console output. I'm not sure what's "unexpected" about the responses as it says but you'd have better idea:

2017-07-19 12:10:35.041 <app>[36795:4216983] unexpected response data (uploading to the wrong URL?)
{
  "name": "resultJsonByContentHash/6ed53b7c3644a09c6580df6618a83878dca12adfb96808191614d81870dfe06e",
  "bucket": "<app>.appspot.com",
  "generation": "1500491432167974",
  "metageneration": "1",
  "contentType": "application/json; charset=UTF-8",
  "timeCreated": "2017-07-19T19:10:32.114Z",
  "updated": "2017-07-19T19:10:32.114Z",
  "storageClass": "STANDARD",
  "size": "142",
  "md5Hash": "k51sAnGeQxIcYOpOMRNqUg==",
  "contentEncoding": "identity",
  "contentDisposition": "inline; filename*=utf-8''6ed53b7c3644a09c6580df6618a83878dca12adfb96808191614d81870dfe06e",
  "crc32c": "i/ZmwQ==",
  "etag": "CKaUtpaGltUCEAE=",
  "downloadTokens": "22acd7d5-e282-423f-96ac-491470c31fca"
}
2017-07-19 12:10:35.043 <app>[36795:4216983] beginChunkFetches has unexpected upload status for headers {
    "Access-Control-Allow-Origin" = "*";
    "Content-Length" = 694;
    "Content-Type" = "application/json; charset=UTF-8";
    Date = "Wed, 19 Jul 2017 19:10:32 GMT";
    Server = UploadServer;
    "access-control-expose-headers" = "X-Firebase-Storage-XSRF";
    "alt-svc" = "quic=\":443\"; ma=2592000; v=\"39,38,37,36,35\"";
    "x-content-type-options" = nosniff;
    "x-guploader-uploadid" = "AEnB2UpMWzXC6bN6D0doRq06GXyj5QfDHUs_32sHigo83Wvoby86cHt2AOlNpTcPB4U8MO_186ogWDcTtthag1uZql6iAFHFdA";
}
2017-07-19 12:10:35.044 <app>[36795:4216983] Premature failure: upload-status:"(null)"  location:(null)

FYI, it's not my security rules being the issue, I haven't changed the default rules (below) and I have firebase.auth().signInAnonymously() before the storage calls.

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

@fungilation
Copy link
Contributor

Bump. I want to debug this, if I can help. Any idea about the Xcode error output?

@Salakar
Copy link
Contributor Author

Salakar commented Aug 14, 2017

v3 docs are being updated for storage, check out the releases once it's done.

@Salakar Salakar self-assigned this Sep 7, 2017
@chrisbianca
Copy link
Contributor

Closing this as we've got internal tasks for documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: storage Firebase Cloud Storage
Projects
None yet
Development

No branches or pull requests

4 participants