I am building an android app and I need to add security rules to Firebase Storage. My App has groups and the file path on storage is /{groupId}/Images/{allPaths=**} and I want to give read and write permission to the members of that group. How can I pass a list of uids to customMetadata() and add corresponding rule for that. Another question is about the rules for write permission: In Firebase, an image is uploaded first and then its metadata can be updated. So if a write rule contains some check on metadata, won't it fail at the time of upload?
PS: I have tried various solutions but all of them failed. One solution was to add uids as keys in customMetadata() and keep value as empty string. But even this didn't work. Any help is appreciated. Thanks.
Update: I added uids as keys in customMetadata() and it worked in read mode security rule but I am still facing error in write mode because while uploading file request.resource.metadata is null.
I solved this issue. I was updating metadata after file upload whereas I had to add metadata during file upload. Refer to Add File Metadata section in the docs: https://firebase.google.com/docs/storage/android/upload-files
Related
Im trying to read a json file from an external storage without sucess. Im getting the error:
Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord{bfaa1d6 26301:com.plm.valdecillasurdemo/u0a284} (pid=26301, uid=10284) requires that you obtain access using ACTION_OPEN_DOCUMENT or related API
My manifest.xml file is OK
I am checking in runtime for READ_EXTERNAL_STORAGE permission and only read the file when the permission is granted
When I try read the file I getting the related error.
In a second approach I started an ACTION_OPEN_DOCUMENT Intent.
A system dialog ask me for picking a file and all is fine. I read the file correctly however I dont want be asked for a Uri. My Uri is hardcoded.
I know must be easy the solution but this problem is drives me crazy...How can I resolve this?
Thanks in advance.
My Uri is hardcoded
That is not possible. You do not have rights to such a document, even if the Uri is valid (which it won't be, since the DocumentsProvider did not do any work on its side to grant it). Beyond that, the user may not have a document at the location that you hard-coded.
How can I resolve this?
Use ACTION_OPEN_DOCUMENT and allow the user to choose the document to remove.
Or, use filesystem locations that you can read and write across OS versions, mostly those defined on Context: getFilesDir(), getCacheDir(), getExternalFilesDir(), getExternalCacheDir(), etc. In this case, you will not need to work with Uri values.
I am trying to upload a file directly to Google Cloud Storage using Java Client Library
The Code I have written is
Instead of uploading the new file to cloud storage I am getting this output
What I am missing in the code to make the upload to Cloud Storage ?
You need configure the the authorization keys, is a file .json to you enverioment,see this in the documentation https://cloud.google.com/iam/docs/creating-managing-service-account-keys#iam-service-account-keys-create-gcloud
I don't think you have the correct "BUCKET_NAME" set, please compare the bucket name you are using with your bucket name on your Google Cloud Console so you can see if it's set correctly.
The way it's set, it looks like the compiler thought you were using a different constructor for your blobInfo.newBuilder method.
I've been looking at Google Cloud Storage. I upload files in my Java program by calling BlobstoreService.createUploadUrl with UploadOptions specifying the default bucket name for the cloud project.
The files appear in the console under the default cloud storage bucket, but the delete button is always disabled. Obviously I'm missing something.
You have to enable the billing to delete file on GCS. When you will enable billing, delete button will be enable.
Hope I can help you..
I've found a way that the buttons are not disabled. Using the storage browser from the regular project console the address is:
https://console.developers.google.com/project/projectname/storage/browser/projectid.appspot.com/?authuser=0
The buttons are disabled at that address. But this one seems to have the buttons working fine:
https://console.developers.google.com/storage/browser/projectid.appspot.com/
answer is here
The files delete with gsutil, no billing enable required.
The disabled buttons referred to in the question are not consistent with this documentation which says:
"Each app can have a default Google Cloud Storage (GCS) bucket that is ready to use with no further activations, configurations, or permission settings required."
Or this which states:
"The bucket is simply there and ready to use, with a free quota. You do not need to make your app billable if you use this option.
Looks like the disabling is a mistake.
Last couple of days I was trying to copy data entities from one appengine application to another. I read that this can't be done for Java application. I made some more research to do that by cloud storage patg but found out that I can't do that between two applications.
Can anybody help on that, and what steps should I do that so can copy data entities from application to another, take in consideration that I want to do that from UI not code.
Now when I try to copy data from app1 to app 2 from Datastore admin it gives :
"There was a problem kicking off the jobs.
The error was:
Fetch to https://blablabla.appspot.com/_ah/remote_api failed with status 404
Back to Datastore Admin"
Please help.
Thanks in advance.
Mohammed.
To restore backup data from a source application to a target application:
Create an access control list (ACL) on the source application's storage bucket with the following permission:
User
[PROJECT_ID]#appspot.gserviceaccount.com
Reader
where [PROJECT_ID] is the project ID of the target application.
https://cloud.google.com/appengine/docs/python/console/datastore-backing-up-restoring#restoring_data_to_another_app
I am writing an application for android and i wish to be able to sync content from a web server, IE: The layouts XML to the device and cache it so that if the device is not connected to the internet it uses an old version of the XML so as soon as the device is on the internet is able to update and gather the latest XML.
Couldn't find much on the internet, so if someone could point me in the right direction or give me some ideas this would be quite helpful.
Cheers,
Alex
This is how it works with a normal xml file:
Create an on your device HTTP Client
Prepare a GET request to your server
Send the request and retrieve the HTTP Response
Read the content using an InputStreamReader
Write the Stream to a file on the external storage name it e.g. newes_version.xml
catch all exception, and just use the file newest_version.xml file.
But it can't work for Layout files
Why? Every time you load your app on an device, everything (except /raw) in the /res folder is being compiled. Therefore your 'stylsheets' doesn't exist anymore the way they did in your IDE. It's not as simple as in html/css where you can just exchange on file. (Well, you can, put not an runtime)
Solution
If you really want to change your layout on Run time, you would have to load the xml (see above), parse it, and apply the information given by file using the R.id reference of the View elements.