1

I'm learning firebase and there are some question with Firebase Storage:

  • Limit of total file size that I can use ?
  • I want use firebase datastorage to upload use avatar then use that url to load image to imageview with glide or picasso. Is it possible?
  • I want use My app with firebase authenticate to make use login, firebase messaging to push notification, firebase database to save some small data, firebase analytic, and database storage. But my account is free. How to I calculate number current access concurrent ? (I want find a solution to it unlimit) If I use many service of firebase number concurrent access will it create?
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
mdtuyen
  • 4,470
  • 5
  • 28
  • 50

2 Answers2

3

Question 1:

5 TB per file, of course limited also by your current plan.

https://stackoverflow.com/a/37971182/2254886 https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload

Here is one method to limit it: https://stackoverflow.com/a/38427527/2254886

Question 2:

Yes, you can both store and retrieve the data in the storage bucket. You can easily get the URL (public or private, your choice) programatically.

Question 3 (well, it's a lot of questions):

https://firebase.google.com/pricing/

You can use that calculator to see which plan you will need depending on your estimated usage. Also, you can see in your console all the analytics to include the number of users. You can find a surprising amount of information in that console.

You can see, the answers to all of your questions are here on SO already. I would encourage you to read through the docs on https://firebase.google.com and maybe head over to the Firebase YouTube channel (https://www.youtube.com/user/Firebase). You can learn everything you need to know on there. Firebase is a very powerful tool for app development.

Community
  • 1
  • 1
Ryan
  • 1,988
  • 4
  • 21
  • 34
  • Hi, @Ryan. I have more question (I'm use account free) Question 1: 5TB/file is very big is it for free member ? but sum of all file, it is unlimit ?Question 3: as I know with FCM I have 100 current access concurent, that mean if only 100 user use my app can be use the app coccurrent ? number user will decreate with I use more service as database, storage, analytic ? – mdtuyen Sep 27 '16 at 00:18
  • Hello @phongvan. Yes, the 5TB per file is larger than the free account can even store, so that shouldn't be a problem. As for the 100 concurrent users, that limit is for the database connection. On the unlimited plan it is 10,000. The 100 users shouldn't decrease for both storage and database connections, just database I believe. – Ryan Sep 27 '16 at 00:49
  • It is my pleasure. – Ryan Sep 27 '16 at 01:21
1

Go to Firebase console -> Storage -> allow test mode(if you want to read and write) create a react app

  • Create a file firebase/firebase.utils.js

     import firebase from 'firebase/app'
     import 'firebase/storage'
    
     // copy config from firebase web app project
     const config={
     apiKey: "your api key",
     authDomain: "auth domain",
     projectId: "web app name",
     storageBucket: "storage bucket",
     messagingSenderId: "sender ID",
     appId: "app id",
     measurementId: "measure id"
     };
    
     export const app=firebase.initializeApp(config)
     export default firebase;
    
  • Go to App.js

     import {app} from './firebase/firebase.utils.js'
     function App() {
     const onChange = (e) => {
     const file = e.target.files[0];
     const storageRef = app.storage().ref()
     const fileRef = storageRef.child(file.name)
     fileRef.put(file).then(() => {
      console.log("Uploaded a file")
    })
    }
    
     return (
    
     <input type="file" onChange={onChange}/>
    
    );
    }
    
    export default App;
    

In this if you want download link to firebase file then apply following changes to onChange

Note-> Allow read access to firebase storage using allow read: if true;

 const onChange = (e) => {
 const file = e.target.files[0];
 const storageRef = app.storage().ref()
 const fileRef = storageRef.child(file.name)
 fileRef.put(file).then(() => {
  fileRef.getDownloadURL().then(function (url) {
            console.log(url);
           
 });
   console.log("Uploaded a file")
  })
}

Rules

If you want to limit upload size to firebase go to rules under storage and use the following rules:
//this rule will allow uploading any files upto 10mb

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read: if true;
      allow write: if request.resource.size < 10 * 1024 * 1024;
                   
    }
  }
}

If you want to allow only images

  rules_version = '2';
  service firebase.storage {
  match /b/{bucket}/o {
  match /{allPaths=**} {
  allow read: if true;
  allow write: if request.resource.size < 10 * 1024 * 1024
           && request.resource.contentType.matches('image/.*');
               
  }
 }
}

If you only want write access delete allow read: if true;

Arihant Jain
  • 817
  • 5
  • 17