邓平洲
邓平洲

Reputation: 11

how to get s3 object key by object url when I use aws lambda python?or How to get object by url?

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

Answers (2)

Radu Diță
Radu Diță

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

Stargazer
Stargazer

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

Related Questions