Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

amazon web services - Convert S3 object name into S3 object url (python)

I uploaded an image called

'Pepper, Pig (#PP).jpg'

to my S3 bucket. I noticed that the corresponding object url created by AWS is:

'Pepper#2C+Pig+(%23PP.jpg)'

In other words, it converts all of the spaces into + and converts the comma and the hash into hex. It does not change the parentheses.

Does this type of encoding have a special name? And is there some way to convert strings into this AWS object url naming convention?


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

1 Answer

0 votes
by (71.8m points)

As John pointed out in the comments, the AWS title is url encoded, so in python, so to convert the S3 object name to the S3 object url, we can just use:

import urllib
object_name = 'Pepper, Pig (#PP).jpg'
object_url = urllib.parse.quote_plus(title)

The results is:

'Pepper%2C+Pig+%28%23PP%29.jpg'

Which works perfectly as when referencing this object in S3.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...