Firebase download URL doesn't work. ERROR 403 / no permission - android

I am creating an app that uploads a photo to the real-time database by saving in under a token as a getDownloadUrl ()
Exemple for a url: https://firebasestorage.googleapis.com/v0/b/reshetgoonmedicalbook-d9a44.appspot.com/o/Briza%2F2022%2F%D7%A8%D7%A4%D7%95%D7%90%D7%99%2F%D7%A0%D7%95%D7%91%D7%9E%D7%91%D7%A8%2F%D7%91%D7%93%D7%99%D7%A7%D7%94%20%D7%91%D7%93%D7%99%D7%A7%D7%94-000000000%2F1669726258516.jpg?alt=media&token=3030d9f7-b501-48ec-a0e0-e00d77ee95f5
And it shows the img on the app from the same url.
The problem is that for the first couple of times everything works fine,i can download the photo and see it but randomly for random urls it stops working.
I am creating an app that uploads a photo to the real-time database by saving in under a token as a getDownloadUrl ()
Exemple for a url: https://firebasestorage.googleapis.com/v0/b/reshetgoonmedicalbook-d9a44.appspot.com/o/Briza%2F2022%2F%D7%A8%D7%A4%D7%95%D7%90%D7%99%2F%D7%A0%D7%95%D7%91%D7%9E%D7%91%D7%A8%2F%D7%91%D7%93%D7%99%D7%A7%D7%94%20%D7%91%D7%93%D7%99%D7%A7%D7%94-000000000%2F1669726258516.jpg?alt=media&token=3030d9f7-b501-48ec-a0e0-e00d77ee95f5
And it shows the img on the app from the same url.
The problem is that for the first couple of times everything works fine,i can download the photo and see it but randomly for random urls it stops working.
Exemple for how the error looks like in the app(blank square): the numbers of the blank squares are still the same as the numbers of the links
And when i try the url from the realtime database. Some urls works and other give me the ERROR 403 no permission
The rules are; { "Rules":{ "read":true, "write":true } }

Related

Browsers insert repeatedly '#10;' in base64 string on every new line?

I want to show on browser already received jpg images coded as Base64.
1. So I upload jpg images to my backend.
2. Then I want to show that uploaded image on the browser.
On Safari it work properly and I have following inspection:
src="data:image/jpeg;base64,_9j_4AAQSkZJRgABAQAAAQABAAD_2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH...
But on every other browser I can't see the very same image, due to the fact that the other base64 tag has repeated occurances of #10; in between the base64 as:
src="data:image/jpeg;base64,_9j_4AAQSkZJRgABAQAAAQABAAD_2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQE...
So other browsers do obviously insert a #10; whereever a new line takes place..
I make the uplod from Android Smartphones and I encode to base64 via:
Base64.encodeToString(jpgStream.toByteArray(), Base64.URL_SAFE);
How can I fix that? Is that backend related or browser or even Android client?
I think something is encoding your \n to
on the server side, and Safari is removing it again, rather than other browsers adding it in.
This HTML works fine in chrome for me (save it in a file called a.html on your desktop and open it):
<html><body><img src="data:image/png;base64, iVBORw0KGgoAAAAN
SUhEUgAAAAUA
AAAFCAYAAACNbyblAA
AAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg=="></img></body></html>
I think you might need to put more code in your question showing how you retrieve the data, base64 it, incorporate it into the page being sent to browser etc
Also, take a look at the raw responses from your server, in the browser developer tools or a web debugging proxy like Fiddler, to see exactly what your server is sending - using Inspect Element might be showing you the data after it's parsed/interpreted/rendered rather than raw

Uploading image to Firebase Storage gives exception [duplicate]

When users log in with Facebook (the only way to log in currently), and want to post something, I run some code to upload their profile picture first, so other users can see who the original poster is. It seems like I can get the user's profile picture Uri which is for example (taken from debug mode):
https://graph.facebook.com/(FACEBOOKID)/picture?height=200&width=200&migration_overrides=%7Boctober_2012%3Atrue%7D
However, when I run:
StorageReference posterPicture = mStorage.child("UsersPictures").child(profile.facebookID);
posterPicture.putFile(profile.profilePictureURI).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {...});
It throws an error saying "no content provider"
W/System.err: java.io.FileNotFoundException: No content provider: https://graph.facebook.com/(FACEBOOKID)/picture?height=200&width=200&migration_overrides=%7Boctober_2012%3Atrue%7D
Error Code: -13000,
HTTP Response Code: 0
Thanks
The short answer is that the URI has to be a file on your file system (you have to download it and re-upload it), or you need a content resolver that can handle HTTPS scheme'ed files.
That said, my question to you is: why? The file is already hosted on Facebook and easily retrievable by that URL, so why upload it again? You can very easily store and share that URL in the Firebase Realtime Database, no need to pay to host in in Firebase Storage.

Firebase storage URL keeps changing with new token

I'm trying to build a social media application using firebase database and storage. Below is the flow expected.
User upload a profile picture which is stored on firebase storage in the current user folder and the URL stored in firebase database for quick access. (Works fine)
User post their thoughts. This save users info such as post message, username and profile image URL in databases. (Works fine).
Problem
The problem now is say a user updates he's or her profile picture, this overrides the older profile image in firebase storage (in order manage storage and to make user image be the same across all comments and post). On the post message activity the older profile image URL can't be accessed cause the token as changed.
Question
I will like to know how this can be fixed in such that the firebase storage URL will be static (that is the same) accross all updates.
NB
Using Picasso and not firebase method to get the images
Although this question had been asked for a very long time, but I noticed some people still find it difficult solving this, so I will be providing my solution below.
STEP 1
Since storage URL are always dynamic (i.e the posses token) when changed, what I did was to use generic name for image file stored say avatar for all users
STEP 2
Create a directory in storage for each user as follows: users/{uid}/avatar.jpg
STEP 3
Pull or display the image by using the path in step 2 (see below)
ANDROID
StorageReference storageReference = FirebaseStorage.getInstance().getReference("users").child(userId).child("avatar.jpg");
Glide.with(context).using(new FirebaseImageLoader()).load(storageReference).diskCacheStrategy(DiskCacheStrategy.ALL)
.error(R.drawable.ch_white_icon).placeholder(R.drawable.ch_white_icon).into(imageView);
WEB
var storage = firebase.storage();
var pathReference = storage.ref('users/' + userId + '/avatar.jpg');
pathReference.getDownloadURL().then(function (url) {
$("#large-avatar").attr('src', url);
}).catch(function (error) {
// Handle any errors
});
With this you don't have to worry with the dynamic link anymore, whenever you upload a new image to the above path, it overrides the previous one and the code in step 3 will give you the new image.
PS: For Android Don't forget to change DiskCacheStrategy.ALL to DiskCacheStrategy.NONE if you don't want glide to cache image or you can use timestamp to get new image if cache is allowed.
Since the URL image is stored in the database, you could use a Cloud Function to update the value after a user has updated his picture.
You can trigger a Cloud function in response to the updating of files in Cloud Storage, see:
https://firebase.google.com/docs/functions/gcp-storage-events
You will find examples of Cloud Functions at: https://github.com/firebase/functions-samples
and the full doc at: https://firebase.google.com/docs/functions/

Error when trying to upload facebook Uri to Firebase Storage

When users log in with Facebook (the only way to log in currently), and want to post something, I run some code to upload their profile picture first, so other users can see who the original poster is. It seems like I can get the user's profile picture Uri which is for example (taken from debug mode):
https://graph.facebook.com/(FACEBOOKID)/picture?height=200&width=200&migration_overrides=%7Boctober_2012%3Atrue%7D
However, when I run:
StorageReference posterPicture = mStorage.child("UsersPictures").child(profile.facebookID);
posterPicture.putFile(profile.profilePictureURI).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {...});
It throws an error saying "no content provider"
W/System.err: java.io.FileNotFoundException: No content provider: https://graph.facebook.com/(FACEBOOKID)/picture?height=200&width=200&migration_overrides=%7Boctober_2012%3Atrue%7D
Error Code: -13000,
HTTP Response Code: 0
Thanks
The short answer is that the URI has to be a file on your file system (you have to download it and re-upload it), or you need a content resolver that can handle HTTPS scheme'ed files.
That said, my question to you is: why? The file is already hosted on Facebook and easily retrievable by that URL, so why upload it again? You can very easily store and share that URL in the Firebase Realtime Database, no need to pay to host in in Firebase Storage.

How To Upload File in Media Fire if it take time more than 10 minute

I am integrating Media Fire Drive In My Mobile application. I have read the Media Fire Api. And Right now I'm able to Download, Upload, Delete, Update everything works fine. But I'm getting problem in uploading.
I am using Multipart for uploading By reading this Upload instruction. If File size is Small ie It's take time <10 minutes to upload than it Upload properly. But if it take time >10 minute than getting Message : Upload Failed And Error Code 169. I think this is problem with Session Token which expire after 10 minutes. Please help me how to Upload If It take time More than 10 minutes.
If your uploads are serialized you can upload with a Type 2 Session Token (and signature) or you can perform and upload with an upload class Action Token.
#Cropper, one alternative is upload your files to a Virtual Server(some providers has a lot of bandwidth for free per example), then you send this files to Mediafire.com.

Categories

Resources