Reputation: 11
I use python boto3
when I upload file to s3,aws lambda will move the file to other bucket,I can get object url by lambda event,like
https://xxx.s3.amazonaws.com/xxx/xxx/xxxx/xxxx/diamond+white.side.jpg
The object key is xxx/xxx/xxxx/xxxx/diamond+white.side.jpg
This is a simple example,I can replace "+" get object key, there are other complicated situations,I need to get object key by object url,How can I do it?
thanks!!
Upvotes: 0
Views: 1805
Reputation: 14211
You should use urllib.parse.unquote
and then replace +
with space.
From my knowledge, +
is the only exception from URL parsing, so you should be safe if you do that by hand.
Upvotes: 1
Reputation: 1530
I think this is what you want:
url_data = "https://xxx.s3.amazonaws.com/xxx/xxx/xxxx/xxxx/diamond+white.side.jpg".split("/")[3:]
object_key = "/".join(url_data)
Upvotes: 0