27

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.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • Please edit your post. If its about a file name then use file name everywhere. Starting with the subject. – greenapps Dec 05 '17 at 10:32
  • 1
    I had the same issue using ":" in the file names, check the best practices for defining Key names. – Jorgesys Dec 07 '17 at 19:18
  • 3
    Can you post the code you have used? I check using AWS Java SDK (without android) and it works fine for me with a `=` symbol also – Tarun Lalwani Dec 08 '17 at 07:19
  • @TarunLalwani Yes. I can post it. It is simply straight forward though. Like I have mentioned in my question, it is an issue that I am facing with Android SDK only. It works even on iOS SDK. – Andro Selva Dec 08 '17 at 08:12
  • 1
    If you are the one putting the file in there, you might consider a different encoding, as suggested in this question: https://stackoverflow.com/questions/4395706/base64-encoding-that-doesnt-use-plus-or-equals-characters – Sean F Dec 13 '17 at 18:04

3 Answers3

5

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

Zub
  • 808
  • 3
  • 12
  • 23
A. STEFANI
  • 6,707
  • 1
  • 23
  • 48
1

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
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • I have already mentioned this in my question. I tried url encoding the "=" to "%3D". But still I am not able to download the file. I get only "the specified key doesn't exist" – Andro Selva Dec 08 '17 at 04:53
0

First of all I think you are using CopyObjects method of s3. OR you received a file name from an s3 event or somewhere else which you are trying to download. The issue is aws handles special characters differently when they store the names. If you'll go to s3 console and click on the file name. You'll see the URI which will have different values for special characters like space will be replaced by + like that. So you need to handle the special characters accordingly. Misleading examples wont help you as aws has constraints on file names but if you save them otherwise it will replace them with acceptable characters and your actual file name will be different than the one you uploaded hence you getting file not found

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 17 '22 at 10:03