简体   繁体   中英

AWS S3 SDK for PHP: how to get object key from its URL?

Since I'm working on legacy code, I would prefer to keep storing objects' URL and not storing their keys. Is there any way to get a key from an URL or must I store keys when I upload files?

In general public url to object looks like:

'https://s3-eu-west-1.amazonaws.com/your-bucket/your-directory/file.txt'

where your-directory/file.txt - is key to object, hence you can parse key from URL.

But I'd rather keep key in my db because it's easier to work with S3 SDK because you have to provide this key to each method which work with objects in S3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM