Thursday, December 14, 2017

Unable to download file with special character from Amazon S3

Leave a Comment

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.

3 Answers

Answers 1

If you are the one putting the file in there, you might consider a different encoding, as suggested in this question: base64 encoding that doesn't use "+/=" (plus or equals) characters?

Answers 2

The following characters in a key name may requiere 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:

enter image description here

The best practices to ensure compatibility between applications defining Key names are using:

- Alphanumeric characters [0-9a-zA-Z] - Special characters !, -, _, ., *, ', (, and ) 

Using android you need to encode the file name, the character (commonly used as operator):

= 

to :

%3D 

Answers 3

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

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment