noway - PUBLIC
  • DOCS FOR THINGS
  • _ref
    • Working Memory
    • NASA’s 10 rules for writing mission-critical code
    • React Native
  • _docs
    • Cryptography
    • Store APIs Key in FrontEnd SDK issues
    • APIs abuse issues
    • Webpack
    • Specific things
      • Text recognition
    • Book reviews
      • April 2020
      • 1-2/2020
      • March 2020
    • Visualization
    • MacOS
    • Go
    • Server
      • Easy way to setup a local HTTP Server on macOS
    • React
    • Reading
    • Tips
      • MVP
      • Sleeping in the right way
      • Get more things done
    • VS Code
      • Intelligent doesn't auto complete the JSX attribute or react-native components
      • Setting.json
    • Service Registration
      • Apple Enterprise Developer Account
    • DevOps
      • Using NGINX for ReactJS
    • Firebase
      • Upload image
      • Save data
      • Save Data with unique key
      • Setup local firebase functions
    • Documentation
      • API Documentation
    • React Native
      • Tips
      • Performance
      • Patterns in React
      • Rendering in React
      • View JS from apk
      • Flatlist with large data list causes blank view
      • Facebook SDK
      • Screen Events
      • Hotkeys
      • Deep Links
        • iOS Deep Link: Universal Link vs URL Schemes‌
        • Deferred Link‌
      • Text going off screen with flexDirection: 'row'
  • _posts
    • 2020-07-13-How-to-Understand-things
    • 2019-02-20-how-to-create-Jekyll-blog-with-github-page
    • 2019-03-01-books-02-19
    • 2019-02-11-highlight-the-pragmatic-programmer-part-01
    • 2019-02-15-highlight-the-pragmatic-programmer-part-03
    • 2019-02-14-highlight-the-pragmatic-programmer-part-02
    • 2019-04-11-books-03-19
    • 2019-03-07-telegram-bot-as-a-real-time-logger
    • 2019-02-04-generic-loading-ios
    • 2019-01-31-summary-books-01-19
    • 2019-03-27-short-polling-with-Swift
    • 2019-02-22-try-catch-exception-rather-than-return-codes
    • 2019-09-29-api-docs
  • category-archive
  • tag-archive
Powered by GitBook
On this page

Was this helpful?

  1. _docs
  2. Firebase

Upload image

PreviousFirebaseNextSave data

Last updated 5 years ago

Was this helpful?

  1. If the file path looks like file:///.... You can just simple put it to Firebase function, don't need readFile step.

My code works properly up to now:

  static uploadProfileAvatar(userID, fileURI) { // file URI is a path of a local image
    const updateTime = moment().unix();
    const storagePath = `${PROFILE_AVATAR_PATH}/${userID}_${updateTime}.jpg`;
    const fileMetaData = { contentType: 'image/jpeg' };
    return FirebaseStorage.uploadFile(fileURI, storagePath, fileMetaData);
  }

  static uploadFile(fileURI, storagePath, fileMetaData = null) {
    const uploadTask = firebase.storage().ref().child(storagePath).put(fileURI, fileMetaData);
    return uploadTask;
  }
  1. If you have the path like rct-image-store://0. You have to write it to and then get the local path image.

ImageStore.getBase64ForTag(
rctFileURI, // rct-image-store: path
(base64Image) => {
  const imagePath = `${RNFS.DocumentDirectoryPath}/${new Date().getTime()}.jpg`;
  RNFS.writeFile(imagePath, `${base64Image}`, 'base64')
  .then((success) => {
    // now your file path is imagePath (which is a real path)
    if (success) {
      // upload with imagePath, same as the 1
    }
  })
  .catch(() => {});
},
() => {},
);

https://stackoverflow.com/questions/58785194/react-native-upload-image-to-firebase-storage/58848809#58848809