7

If I have a file name that is

a'd1 & "[tttt]" + 'sq.jpg

When this gets uploaded to Amazon S3, it gets converted to this

a'd1 & %22[tttt]%22 + 'sq.jpg

So the double quotes are URL encoded and the filename itself is changed.

The file has to be fetched using the encoded URL

a%27d1+%26+%2522%5Btttt%5D%2522+%2B+%27sq.jpg So the encoding rules seem to be:

": %2522  (double encoded)
Space: + 
&: %26 
[: %5B
]: %5D
+: %2B 

Is there a way to determine all the rules that S3 requires? Normal javascript encoding with (encodeURI or even encodeURIComponent) won't work

sat
  • 5,489
  • 10
  • 63
  • 81
  • > "When this gets uploaded to Amazon S3, it gets converted to this" _How_ did you upload it? It's quite possible that there is a bug in the tool you used. – Ryan Parman Jan 13 '14 at 09:01
  • why do you say that `encodeURIComponent` won't work? as far as I can see the onyl difference that and between what you're describing is that `encodeURIComponent` encodes space as %20. However, %20 also works with s3 so I don't see any problem using it – Andy Jul 31 '23 at 08:27

1 Answers1

6

This is not from a definitive source, but it has worked for my requirements: encodeS3URI

It replaces the following characters +!"#$&'()*+,:;=?@

S3 replaces spaces in filepaths with +, so its best to do the URI encoding before any further string replacements

amigolargo
  • 800
  • 2
  • 7
  • 24
  • 3
    Just to highlight this again, if you upload it with spaces it changes to + if you then later come back and upload it with + it changes it to %2B – Morgeth888 Jul 24 '18 at 16:53