Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 views
in Technique[技术] by (71.8m points)

amazon s3 - What are valid S3 key names that can be accessed via the S3 rest API?

From the AWS docs, I understand that:

  • S3 key names can be any UNICODE name < 1024 chars
  • When using the GET OBJ, I need to URL encode the key name to access it.

However, these rules seem too permissive.

For instance, if I make a key called '../../d', a 400 ERROR occurs when I attempt to access it with the GET OBJECT API. Interestingly, I have no problem accessing '../d'.

Is there a document specifying what is and is not legal?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According to AWS S3 documentation:

Although you can use any UTF-8 characters in an object key name, the following key naming best practices help ensure maximum compatibility with other applications. Each application may parse special characters differently. The following guidelines help you maximize compliance with DNS, web safe characters, XML parsers, and other APIs.

Please find below the

Object Key Naming Guidelines from the AWS S3 official documentation


Safe characters

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

  • Alphanumeric characters: 0-9 a-z A-Z
  • Special characters: ! - _ . * ' ( )

NOTE ABOUT THE DELIMITER ("/")

The following are examples of valid object key names:

  • 4my-organization

  • my.great_photos-2014/jan/myvacation.jpg

  • videos/2014/birthday/video1.wmv

Note that the Amazon S3 data model is a flat structure: you create a bucket, and the bucket stores objects. There is no hierarchy of subbuckets or subfolders; however, you can infer logical hierarchy using keyname prefixes and delimiters as the Amazon S3 console does.

e.g if you use Private/taxdocument.pdf as a key, it will create the Private folder, with taxdocument.pdf in it.

Amazon S3 supports buckets and objects, there is no hierarchy in Amazon S3. However, the prefixes and delimiters in an object key name, enables the Amazon S3 console and the AWS SDKs to infer hierarchy and introduce concept of folders.


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 ("&")
  • 'At' symbol ("@")
  • Colon (":")
  • Comma (",")
  • Dollar ("$")
  • Equals ("=")
  • Plus ("+")
  • Question mark ("?")
  • ASCII character ranges 00–1F hex (0–31 decimal) and 7F (127 decimal.)
  • Semicolon (";")
  • Space – Significant sequences of spaces may be lost in some uses (especially multiple spaces)

Characters to Avoid

You should avoid the following characters in a key name because of significant special handling for consistency across all applications.

  • Backslash ("")
  • Caret ("^")
  • Grave accent / back tick ("`")
  • 'Greater Than' symbol (">")
  • 'Less Than' symbol ("<")
  • Left curly brace ("{")
  • Right curly brace ("}")
  • Right square bracket ("]")
  • Left square bracket ("[")
  • 'Pound' character ("#")
  • Non-printable ASCII characters (128–255 decimal characters)
  • Percent character ("%")
  • Quotation marks
  • Tilde ("~")
  • Vertical bar / pipe ("|")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...