Image upload failed to firebase database - android

This is the code for taking the image, and the logcat error. I suspect there is problem with the permissions in phone. By default the application shows no permissions in phone. Is there a way to give permissions explicitly through the code?
logcat error message
code used for taking image input
I checked permissions on phone, I am developing this project by seeing an older video in youtube. So there is a chance of updation problem.

There isn't any issue with your application or device.
You haven't set proper permission on firebase storage.
Firebase storage requires user to be authenticated.
But if you are just testing Storage you can by-pass that rule.
In the Storage > Rules, add below code block,
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth == null;
}
}
}
Note:
It's good practice to protect the firebase storage with authentication. So after testing storage feature, please update rules accordingly.

Related

How And Where Do Meditation Apps Store Their Audio Files?

I'm building a Flutter app that plays audio files. I have hundreds of audio files that are too large to store in the app. So, I want to host the files, then stream them to the device.
I'm using the just_audio package (https://pub.dev/packages/just_audio). I've tested my code using the following hosted audio file and it works... (https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3)
However, when I try to play my own audio files from Google Storage it doesn't work. Google gives me a storage location that looks like this (gs://myappname.appspot.com/audio_file.WAV)
So I guess I have two questions.
Is it possible to stream audio files from Google Storage to an iOS or Android app? If so, what am I not doing right? Or should I be using another Google service for this?
If this is not possible, how do apps like Headspace or Calm host and then stream their audio files?
Any advice would be greatly appreciated.
In an attempt to be thorough, here are the rules for my google storage account...
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
// allow access for all users
allow read, write;
}
}
}
I solved this. I was using the wrong address in Google Storage.
Google Storage gives a "storage location" which is the gs:// address I was using. It also gives a download link that I missed.
By using the download link, I solved my problem.

Cloud Firestore: Missing or insufficient permissions

I am getting (on Android):
com.google.firebase.firestore.FirebaseFirestoreException:
PERMISSION_DENIED: Missing or insufficient permissions
using these security rules:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
My app seems to be properly authenticated using FirebaseAuth, as the mFirebaseAuth.getCurrentUser().getUid() returns the proper user ID.
Is there something I am doing wrong?
Edit: just want to say that I managed to fix the issue by downgrading to 4.6.2. I have more details in this post
Pre-edit:
This is happening to me ever since I upgraded react native and I cannot for the life of me figure out the problem. I've debugged it and my user is definitely authenticated at the time of the request, I checked this by running the below and I have a uid in there
firebase.auth().currentUser
So the next thing I wanted to do was check the session in the actual request to see what was happening. I added a piece of code to the entry point of my react app
XMLHttpRequest = GLOBAL.originalXMLHttpRequest ?
GLOBAL.originalXMLHttpRequest :
GLOBAL.XMLHttpRequest
and when I run this code it magically works again. This is delegating requests through the browser though so probably not a true test.
So then I started up Charles and compared the requests for my new react-native build with my old [working] react-native build. The requests look the same to me though (apart from a different sessionId) so I have no idea. The frustrating thing is the lack of debug tools through the firestore console.
My gut is to say some of the auth headers are expired/cached and that it's not firestore. Banging my head against a table at this point
It seem it's a Firestore problem (in beta today), not in the client side.
I asked the Firebase support team directly since this issue was kind of critical for our service and I received the email below. It seems they fixed the bug now.
Please let me know if the issue happens again.
Hi there,
We have just confirmed with our engineers that this sporadic issue
with our Security Rules for Firestore was a known bug but was already
fixed today. Kindly test your security rules again and let us know if
you are still encountering the issue.
Regards, Kevin

Grant unlimited persistence storage permission

Based on the IndexedDB of Cordova Storage documentation, the storage is limited to around 5MB (the last point of the Disadvantages paragraph).
I need far more storage for my app, thus I have to break the jail without any other option.
Round 1: Ask for more storage quota.
navigator.webkitPersistentStorage.requestQuota(quota, function(granted) {
window.requestFileSystem(window.PERSISTENT, granted, cbSucc, cbErr);
}, cbErr);
The 'granted' alway zero no matter what 'quota' is.
There is no requestFileSystem() function in the 'window' object on Android webview.
Based on (https://stackoverflow.com/a/42355894) : it only works for the sandboxed filesystem. Maybe this is not what I need anyway.
Round 2: Implement a Push Notification service worker which will grant persistence storage permission automatically.
navigator.serviceWorker.register('sw.js')
.then(function(swNotify) {
swNotify.pushManager.subscribe({
userVisibleOnly : true,
applicationServerKey : pubKey
});
});
The service worker is registered.
There is no PushManager on Android webview, thus no way to do pushManager.subscribe().
This works fine for Chrome on desktop and Android except webview.
Round 3: Ask for durable storage permission.
navigator.storage.persist().then(...);
The persist() function always returns false without asking user to grant permission.
The WRITE_EXTERNAL_STORAGE permission is already requested and granted.
Environment :
Android: 7.0 (by Android Emulator)
WebView: 58.0.3029.83
Cordova: 7.0.1
andorid platform of Cordova: 6.2.3
I am still a prisoner of the 5MB jail, what can I do else?
You could use the cordova-sqlite-storage plugin to create a native SQLite database with unlimited storage:
Unlike IndexedDB (and WebSQL) which are integrated into the Webview, this uses a native database which is stored in a .db file on disk.
Currently there is no IndexedDB interface shim (although it's on the TODO list) so you'd need to rework the API calls to the database. However there is, for example, an adapter for Lawnchair which makes for an easy-to-use API.

addOnfailurelistener being called when I try uploading an image to firebase storage

pic2I am new to firebase storage and I am trying to upload an image to firebase just so I could learn it. My app has a button. When I click on it. Image gets displayed on image view. The image gets displayed correctly, but that image is not stored to firebase storage. I have added the necessary code (OnClickListener of buttonpic1) from firebase website to upload that image to storage. But the image isnt uploaded and addOnfailurelistener gets called (I am using a toast in this method). Can anybody let me know why it is not being uploaded on firebase?
Firebase needs Google Play Services version 9.4.0 or newer in order to work, as explained here, so try to update it and check again.
Also, check if you have specified the appropriate rules for your Firebase Project. By default, Firebase Storage allows only authenticated users, but you can change it to public.
Go to the "Rules" tab of the "Storage" section in the console, and replace the code you see by that:
service firebase.storage {
match /b/your-bucket-id.appspot.com/o {
match /{allPaths=**} {
allow read, write;
}
}
}
where your-bucket-id put the address shown in the "Files" tab in the console (without gs://).

Grant permission to everyone with Amazon S3 upload

After uploading a file with the TransferUtility for Amazon S3, I can't use the file.
Request failed 403: Forbidden
When I go to my bucket and check Permissions on the right, it only shows me.
When I add everyone, I can access the file without problems.
I was searching for a way to grant permission while uploading, but could find one for Android.
I found an answer for C# which leads me to this:
CannedAccessControlList cannedAccessControlList = CannedAccessControlList.BucketOwnerFullControl;
but I don't know where to add this..
The easiest method is to define a Bucket Policy that grants public access to a bucket, or a path within a bucket. That way, you do not need to specify the permissions on each individual object.
See: Using Bucket Policies and User Policies
For example, this bucket policy would allow public access to any object stored in the uploads path:
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::examplebucket/uploads/*"]
}
]
}
transferManager.upload(new PutObjectRequest("bucket name", "file name", "file path object").withCannedAcl(CannedAccessControlList.PublicRead));

Categories

Resources