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));
Related
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.
I have published the app on the Google play store with MANAGE_EXTERNAL_STORAGE permission. Google rejected the app and said to remove this permission and get access to a specific folder (related to your app, not the entire storage permission)
I have used the react-native-scoped-storage for this purpose and followed the documentation. With this line:
let dir = await ScopedStorage.openDocumentTree(true);
The file manager opened and I granted permission, but still, I am unable to get files.
I do get files with this same package with this line:
const files = await ScopedStorage.listFiles(dir.uri);
But the format is not correct, I get data in this format:
"uri": "content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2Fmedia%2F.Statuses/document/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2Fmedia%2F.Statuses"
Can anyone help me with this problem? I would really appreciate it. Thank you.
Since Android Q came out there are some privacy changes in the permissions about read from external storage. I have a chat application that the user can choose a photo from Downloads etc... and send it. So i need to have access to that files. The way i did this is by using contentProvider.
context.contentResolver.openInputStream(uri)?.use { inputStream ->
while (true) {
numBytesRead = inputStream.read(buffer)
// .. do stuff
}
}
The uri that is available at that time is -> file:///storage/emulated/0/Download/myFile.pdf
However i get a FileNotFoundException but the file trully exists.
I have set all the permissions in the manifest and granted them on the launch of the app. From Android <= 9 it works properly.
So what do i have to do...?
I have a chat application that the user can choose a photo from Downloads etc... and send it
That will not be possible on Android 10 and higher. You need to switch to something else. For example, you could use ACTION_OPEN_DOCUMENT to allow the user to choose content from anywhere the user wants. Then, use the resulting Uri to upload it to your chat server, akin to how you are using the Uri in your code snippet. Or, better yet, don't read it all into memory — use something like this OkHttp InputStreamRequestBody implementation.
For Android 10, you can add android:requestLegacyExternalStorage="true" to your <application> element in the manifest. This opts you into the legacy storage model, and your existing external storage code will work. That will not work on Android R and higher, though, so this is only a short-term fix.
I have a bucket named foo inside which resides my two subfolders named bar and foobar.
Hierarchy
foo
-bar
-foobar
Problem
Now i want to make my uploaded objects public readable. Using xhr (by allowing CORS) i was able to do so. But using AWS android sdk the public-read acl is still not implemented in their api as specified by this feature request on GITHUB
So as evident i am not able to make my uploaded objects using AWS Android sdk
So please help me in solving this issue.
This can be done via S3 bucket policy. See Bucket Policy Examples. It looks like what you need is to allow anonymous read to objects under a bucket. You can apply the following bucket policy to the bucket foo.
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::foo/bar/*","arn:aws:s3:::foo/foobar/*"]
}
]
}
This should also answer the question on Github.
The transfer manager currently does not support ACL; however, you can use AmazonS3Client to perform putObject(). You can take a look at the AWS Mobile SDK for Android API Reference for more details.
When my app upload to android market,Upload assets have a warnig message about this:
This apk requests 1 permissions that users will be warned about
android.permission.INTERNET
I check the app of manifest.xml,I'm sure there are manifest.xml to join the line
uses-permission android:name="android.permission.INTERNET
so...Why are there warning message about android.permission.INTERNET?
And another question,the Upload assets of "Localized to" appear unknown,
how to set this field about "Localized to"?
thanks~
Your application end users will be notified before installation the application have full access to Internet, something like this (there are 3 permissions, in your case only "Network communication" will appear):
you need to add localized strings first and market will automatically recognizes them.
see developer.android.com reference