Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to download file with special character from Amazon S3

I have been trying to download a file from Amazon S3 that ends with special character. enter image description here

The file name ends with an "=" as a result of Base64 encoding. Now I am trying to download this file and I receive an error,

The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey;

enter image description here

I tried URL Encoding the string. So now the "=" becomes "%3D" and still I receive the same error. But if I remove the "=" from the file name, I am being able to download the file without issues. But this is a common file and it is to be accessed form iOS as well.

NOTE: The iOS Amazon SDK works even when the file name has "=" in it. The issue is faced only in Android SDK.

like image 657
Andro Selva Avatar asked Dec 05 '17 08:12

Andro Selva


People also ask

Why am I getting an HTTP 403 Forbidden error when I try to download files using the Amazon S3 console?

The "403 Forbidden" error can occur due to the following reasons: Permissions are missing for s3:PutObject to add an object or s3:PutObjectAcl to modify the object's ACL. You don't have permission to use an AWS Key Management Service (AWS KMS) key. There is an explicit deny statement in the bucket policy.

Why am I getting an access denied error from the Amazon S3 console when I try to modify a bucket policy?

Short description. The "403 Access Denied" error can occur due to the following reasons: Your AWS Identity and Access Management (IAM) user or role doesn't have permissions for both s3:GetBucketPolicy and s3:PutBucketPolicy.

How do I download an object from Amazon S3?

When you download an object through the AWS SDK for Java, Amazon S3 returns all of the object's metadata and an input stream from which to read the object's contents. Execute the AmazonS3Client.getObject () method, providing the bucket name and object key in the request.

Why am I getting an Access Denied error in Amazon S3?

Check that the bucket policy or IAM policies allow the Amazon S3 actions that your users need. For example, the following bucket policy doesn’t include permission to the s3:PutObjectAcl action. If the IAM user tries to modify the access control list (ACL) of an object, then the user gets an Access Denied error.

How do I store data in Amazon S3?

To store your data in Amazon S3, you work with resources known as buckets and objects. A bucket is a container for objects. An object is a file and any metadata that describes that file.

How to find the Amazon S3 canonical ID for your account?

Run the list-buckets AWS Command Line Interface (AWS CLI) command to get the Amazon S3 canonical ID for your account: Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI. 2.


1 Answers

According to AWS documentation

Safe Characters

The following character sets are generally safe for use in key names:

Alphanumeric characters [0-9a-zA-Z]

Special characters !, -, _, ., *, ', (, and )

and

Characters That Might Require Special Handling

The following characters in a key name may require additional code handling and will likely need to be URL encoded or referenced as HEX. Some of these are non-printable characters and your browser may not handle them, which will also require special handling:

Ampersand ("&")

Dollar ("$")

ASCII character ranges 00–1F hex (0–31 decimal) and 7F (127 decimal.)

'At' symbol ("@")

Equals ("=")

Semicolon (";")

Colon (":")

Plus ("+")

Space – Significant sequences of spaces may be lost in some uses (especially multiple spaces)

Comma (",")

Question mark ("?")

So it confirms you that "=" require special handling, It will be better if you replace the last "=" char with another safe char to avoid the issue ...

Please try to change the "=" to "&#61"


As on iOS, there is no issue, I expect that it could be relative to the Android environment.

You may note that some chars could also be forbidden because the SH or BASH or ANDROID shell environment execution, please also to take in consideration that some disk format option (FAT32 on a normal android external memory card) could also represent a factor which forbids some char in the filename.

If you take a look here and more especially on the @kreker answer:

According to wiki and assuming that you are using external data storage which has FAT32.

Allowable characters in directory entries 

are

Any byte except for values 0-31, 127 (DEL) and: " * / : < > ? \ | + , . ; = [] (lowcase a-z are stored as A-Z). With VFAT LFN any Unicode except NUL 

You will note that = is not an allowed char on the android FAT32 partition ...

As I expect that Android will consider = as restricted char you may try to escape it with a \= or add a quote to the file name on your code ...

An example with a copy:

cp filename=.png mynewfile=.png #before   cp "filename=.png" "mynewfile=.png" #after 

"VCS...=.png"

If nothing of this tricks will work you have to change the filename to remove the "=" when you create those files.

Regards

like image 142
A STEFANI Avatar answered Sep 26 '22 18:09

A STEFANI