I would like to know if this action that I am doing in my application generates expenses for Firebase Storage. That is,
if regardless of the times I do the following action it will generate some expense in Firebase billing.
I have images stored in storage, and I upload these images to an ImageView using the Glide library, like this:
Uri url = Uri.parse(pictureUser);
Glide.with(MainActivity.this).load(url).into(imageView);
I have a chat application, and in each message on the adapter I want to upload the user's photo this way, using Glide, so, as there are many uploads, I wanted to know if every time I run this code snippet, it generates some billing expenses of the firebase.
As you are using this in chat activity this means that same image may probably load many of times.
To decrease the number of images that download I suggest you to use instead of:
Glide.with(MainActivity.this).load(url).into(imageView);
replace it by :
Glide.with(MainActivity.this)
.load(url).diskCacheStrategy(DiskCacheStrategy.DATA)
.into(imageView);
by this way, you are activating the cache mode. this means the Glide will search in the cache if it exists then will upload it from the internet.
I advise you to use Picasso instead of Glide. it works better in mode offline than Glide:
Picasso.with(MainActivity.this)
.load(url)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
// Try again online if cache failed
Picasso.with(MainActivity.this)
.load(url)
.error(R.drawable.user_placeholder_error)
.into(imageView);
}
});
Any time your code download a file, it will be billed as egress from Cloud Storage.
With Glide, it as a disk cache enabled by default, so it should only download a URL once and reuse it from cache (as long as it remains in cache). That would not be billed, since it's not downloading anything from the cloud.
Related
I have to take a picture from the camera of the device and send the image directly into a cloud server, I am very new to Cloud and storage so I need some help with this topic.
I am successfully able to open up the camera and take a picture and store the picture into my local storage. please help me to expand this code.
Main_management::Main_management(QWidget *parent)
: QWidget(parent)
{
cam=new QCamera();
cam->setCaptureMode(QCamera::CaptureStillImage);
view=new QCameraViewfinder();
view->show();
cam->setViewfinder(view);
vb1.addWidget(view,10,Qt::AlignTop);
pb=new QPushButton("capture");
vb1.addWidget(pb,0,Qt::AlignBottom);
this->setLayout(&vb1);
imageCapture=new QCameraImageCapture(cam);
cam->start();
connect(pb,SIGNAL(clicked()),SLOT(Capture_image()));
cam->start();
}
Main_management::~Main_management()
{
}
void Main_management::Capture_image()
{
qDebug()<<Q_FUNC_INFO<<endl;
imageCapture->capture("C:/Users/vinay/Documents");
}
as you can see in the slot i am storing the image onto the local storage please can somone guide me as how to use any cloud storage API's and push the image onto a server.
Assuming that a bucket is already created in Cloud Storage.
To upload the image from your local storage to Cloud Storage use the Cloud Client Libraries for the Google Cloud Storage API. In order to achieve this with C++ you'll basically need to follow three steps:
Installing the client library.
Create a service account, download the service account key and set up an environment variable for authentication.
Create a client and use the client.UploadFile() method to upload the file from your local storage to Cloud Storage.
For steps 1. and 2. please refer to this documentation. Find a comprehensive example code for step 3. on the following section of the documentation.
I am experiencing a strange behavior with my Firestore account, on the console I select a collection then I click Delete all documents an it indicates that all have been deleted successfully. When I refresh the data, the collection appear with all the deleted data. I have no service doing this anywhere and wondering what may cause this. Is there a solution?
Alongside this, any change I do to the document fields on the console are successful but are lost after refreshing.
I experienced similar behaviour today that I haven't seen before. I deleted documents from the Firestore console but my app was still fetching them successfully. Now, about an hour after witnessing that behaviour everything is back to normal and my console deletes are immediately seen on the device.
I'm thinking it was a glitch in Firestore - after all it's still in Beta.
I tried all possible means, I had to back up the whole Firestore DB in Json files then deleted the project from console and created a new one. I think It's an issue with Firestore since I created the project before the launch of Firestore and may have required to create a new one.
This happened to me today (7/1/18). After completely logging out of firebase and then logging back in, I was able to delete documents and have them be permanently removed.
It happens because your app is using the cache memory instead of the actual data. You'll have to disable the cache and re-enable the network.
For iOS:
// disable cache
let settings = FirestoreSettings()
settings.isPersistenceEnabled = false
let db = Firestore.firestore()
db.settings = settings
// call your queries inside this layer
Firestore.firestore().enableNetwork { (error) in
// Do online things
}
For Android/Java:
// disable cache
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(false)
.build();
db.setFirestoreSettings(settings);
// enable network
db.enableNetwork()
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
// Do online things
// ...
}
});
You can read more at https://firebase.google.com/docs/firestore/manage-data/enable-offline
Just trying to figure out something that seemed trivial in firebase, in google-cloud.
It seems as though if you're making a node.js app for HTML (i'm talking to it through Unity actually, but it's a desktop application) you can't use firebase-storage for some odd reason, you have to use google-cloud, even the firebase-admin tools use the cloud storage to do storage from here.
Nevertheless, i got it working, i am uploading the files to the firebase storage; however, the problem is in firebase, you could specify a specific file, and then do storage().ref().child(filelocation).GetDownloadURL(): this would generate a unique url for some set time that can be used publicly, without having to give out access to read to all anonymous users.
I did some research and i need to implement something called GS UTIL in order to generate my own special urls, but it's so damn complicated (im a newbie to this whole server stuff), i don't even know where to start to get this working in my node server.
Any pointers? I'm really stuck here.
-------if anyones interested, this is what im trying to do high level-----
I'm sending 3d model data to node app from Unity
the node app is publishing this model on sketchfab
then it puts the model data onto my own storage, along with some additional data specially made for my app
after it gets signed to storage, it gets saved to my Firebase DB in my global model database
to be accessed later, by users, to try to get the downloadURL of this storage file and send them all back to Unity users(s)
I would just download the files into my node app, but i wanna reduce any server load, it's supposed to be just a middleman between Unity and Firebase
(i would've done it straight from Unity, but apparently firebase isn't for desktop windows apps).
Figured it out:
var firebase_admin = require("firebase-admin");
var storage = firebase_admin.storage();
var bucket = storage.bucket();
bucket.file(childSnapshot.val().modelLink).getSignedUrl({
action: 'read',
expires: expDate
},function(err,url){
if(err){
reject(err);
}
else{
finalData.ModelDownloadLink = url;
console.log("Download model DL url: " + url);
resolve();
}
});
I'm developing an app that will stream mp3 file stored in firebase storage. Nearly I'm having 100 songs like song1,song2,song3..... if a song is selected I have to stream that particular song without downloading. In such case I need to write plenty of code because for each song I have to mention the firebase storage url. the url would be like
https://firebasestorage.googleapis.com/......song1.mp3?alt=media&token=8a8a0593-e8bb-40c7-87e0-814d9c8342f3
For each song the alt=media&token= part of the url varies, so I have to mention the unique url for all songs. But here I need some simplified coding to play the songs by mentioning its name alone from firebase storage.
Please suggest a way to stream the audio file by using its name alone that is stored in firebase storage.
You have two choices if you want to get files out of a Firebase Storage bucket.
Use the full download url that you can get from a Storage Reference that points to the file path in your bucket.
Use a download task (Android or iOS) to fetch the data from the file.
You can't get the file data any other way from within a mobile app. Firebase Storage doesn't support special media streaming protocols, such as RTSP.
I did it using downloadUrl.
val storage = FirebaseStorage.getInstance()
storage.reference.child("songs/song1.mp3").downloadUrl.addOnSuccessListener({
val mediaPlayer = MediaPlayer()
mediaPlayer.setDataSource(it.toString())
mediaPlayer.setOnPreparedListener { player ->
player.start()
}
mediaPlayer.prepareAsync()
})
StorageReference filepath=storage.child("Audio").child(timeStamp+".mp3");
Uri uri=Uri.fromFile(new File(fileName));
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String audio_url=taskSnapshot.getDownloadUrl().toString();
Use audio_urlto stream the audio file using media player
I'm using firebase storage to upload avatars (original.jpg).
In a node.js background process I resize them with gm and then put them back in my firebase bucket. These pictures are publicly readable, see my storage rules :
service firebase.storage {
match /b/xxx.appspot.com/o {
match /images {
match /{allImages=**} {
allow read;
}
match /{userId}/avatar/original.jpg {
allow write: if request.auth.uid == userId;
}
}
}
}
I store the url of images in firebase database ex:
https://firebasestorage.googleapis.com/v0/b/xxx.appspot.com/o/images%2Fyyy%2Favatar%2Fzzz-small.jpg?alt=media
That I retrieved right after the file upload (web sdk) var downloadURL = uploadTask.snapshot.downloadURL; ; stripped off the token parameter as it's gonna be public ; and where zzz-small.jpg has replaced original.jpg.
It works, pictures are displayed.
But it's slow even though the picture is a 40x40px jpg. And it hangs for a while before actually downloading the file, see Chrome Network record :
Chrome network record
The file is 158B, there's a ~1s waiting before the download ~3ms...
Is firebase storage supposed to be as fast as a CDN ?
Any faster way to call a public readable file ?
[EDIT]
Got some feedback from Firebase support :
We're definitely aware that many users, such as yourself, are having
issues with slow downloading of file from Europe. We're exploring
potential solutions, but I can't share any details or timelines at
this time. We'll keep your feedback in consideration moving forward
though.
Keep an eye out on our release notes for any further updates.
I forgot to mention I'm in Europe and the storage in the US.