minio/minio-js

Get a permanent URL for object

sidhantpanda opened this issue ยท 19 comments

Hey, there is provision for getting a preSignedUrl but we need to supply an expiry time.

Is it possible to get a permanent link to the object, so that the url can be saved in the db upon completion of put object request? How to correctly set the bucket policy for this, as the policies listed are not the same as the policies in S3?

@sidhantpanda

There can't be a permanent presigned URL.

What you can do instead is, create objects whose names are:

public/obj1
public/obj2
public/obj3
public/obj4
public/obj5

And make the prefix public/ publicly accessible using this command:
mc policy download myminio/testbucket/public/

more about mc: https://github.com/minio/mc

@krishnasrinivas is there a way to have URLs to public objects without making an API call to Minio? I want to render pages with images and videos served directly from the Minio server.

@krishnasrinivas is there a way to have URLs to public objects without making an API call to Minio? I want to render pages with images and videos served directly from the Minio server.

To list objects one needs to make an API call you can use following CLI to get the list as well alternatively.

mc policy links play/testbucket --recursive 
https://play.minio.io:9000/testbucket/0001-dsync.patch
https://play.minio.io:9000/testbucket/filename.txt
https://play.minio.io:9000/testbucket/mc
https://play.minio.io:9000/testbucket/my-objectname
https://play.minio.io:9000/testbucket/test1
https://play.minio.io:9000/testbucket/test1.txt
https://play.minio.io:9000/testbucket/test2.txt
https://play.minio.io:9000/testbucket/1/ldap/client.go
https://play.minio.io:9000/testbucket/1/ldap/example.go
https://play.minio.io:9000/testbucket/accounts/1.original.jpg
https://play.minio.io:9000/testbucket/accounts/2.original.jpg
https://play.minio.io:9000/testbucket/accounts/c4a3ec89-3adf-40dc-822f-2d5ca8e22e32.original.jpg
https://play.minio.io:9000/testbucket/documents/1_files/issue
https://play.minio.io:9000/testbucket/documents/2_files/issue
https://play.minio.io:9000/testbucket/resumes/4.large.png
https://play.minio.io:9000/testbucket/resumes/4.original.pdf
https://play.minio.io:9000/testbucket/resumes/4.thumb.png

@krishnasrinivas is there a way to have URLs to public objects without making an API call to Minio? I want to render pages with images and videos served directly from the Minio server.

Yes, you can serve images/videos directly from Minio server to web-browser without authentication if you set the the policy on the bucket as "download"

mc policy download myminio/testbucket/

more about mc: https://github.com/minio/mc

After set the policy of specific bucket to download in minio server, we can get the resource public url as follow:

var publicUrl = minioClient.protocol + '//' + minioClient.host + ':' + minioClient.port + '/' + minioBucket + '/' + obj.name

@harshavardhana
I have files successfully stored in Minio. I can list the links to different objects using the command you provided:mc policy links myminio/mybucket --recursive
I have my policies right for the different object and I can access them anonymously.

Is there a way I can get the same results using Python Client API?

In fact what interests me the most is the https://play.minio.io:9000/ since I can append to it the rest of the link. Is that address fix? Is it configurable? etc
Thanks in advance

You have to construct the url yourself. You know endpoint, bucket and you have object name.

@harshavardhana
While debugging, the minioClient in question has only an attribute _endpoint_url which is equal to http://localhost:9000
Using the command:

./mc policy links myminio/mediabucket --recursive
http://172.19.0.3:9000/mediabucket/pexels-photo-620332X.jpeg
http://172.19.0.3:9000/mediabucket/user159/email/pexels-photo-620332XX.jpeg
http://172.19.0.3:9000/mediabucket/pexels-photo-620332.jpeg

How can I retrieve this endpoint: http://172.19.0.3:9000?
I know it is configured in config.json but I don't know what the best approach is, since I don't know if it changes or not, and how would that affect my app once I try to deploy it.

Please come to slack.minio.io for discussion like these, we can avoid discussing here on closed issues or feel free to open a new one under minio-py

These stuff are really useful, but not well documented. The discussion here is confusing but does help at the end. Thanks

@phuyem the documentation is not capturing FAQs ATM. We are working on finishing it for further usefulness and clarity.

@harshavardhana
While debugging, the minioClient in question has only an attribute _endpoint_url which is equal to http://localhost:9000
Using the command:

./mc policy links myminio/mediabucket --recursive
http://172.19.0.3:9000/mediabucket/pexels-photo-620332X.jpeg
http://172.19.0.3:9000/mediabucket/user159/email/pexels-photo-620332XX.jpeg
http://172.19.0.3:9000/mediabucket/pexels-photo-620332.jpeg

How can I retrieve this endpoint: http://172.19.0.3:9000?
I know it is configured in config.json but I don't know what the best approach is, since I don't know if it changes or not, and how would that affect my app once I try to deploy it.

Anyway to hide the port?

Hi,
Is there a way to get these links through a Python API call?
Suggestions would be much appreciated. I know about the presigned_get_object method for the client to fetch the link to the file, which is downloadable, but it is not a direct link to the file like an 's3://bucket-name/file.csv' would do, or even the above link examples would do.
How to fetch such links using Python API is my question/concern. Any suggestions would help! Thank you and appreciate your time reading this.

@harshavardhana
While debugging, the minioClient in question has only an attribute _endpoint_url which is equal to http://localhost:9000
Using the command:

./mc policy links myminio/mediabucket --recursive
http://172.19.0.3:9000/mediabucket/pexels-photo-620332X.jpeg
http://172.19.0.3:9000/mediabucket/user159/email/pexels-photo-620332XX.jpeg
http://172.19.0.3:9000/mediabucket/pexels-photo-620332.jpeg

How can I retrieve this endpoint: http://172.19.0.3:9000?
I know it is configured in config.json but I don't know what the best approach is, since I don't know if it changes or not, and how would that affect my app once I try to deploy it.

Anyway to hide the port?

Use Proxy server

@krishnasrinivas is there a way to have URLs to public objects without making an API call to Minio? I want to render pages with images and videos served directly from the Minio server.

To list objects one needs to make an API call you can use following CLI to get the list as well alternatively.

mc policy links play/testbucket --recursive 
https://play.minio.io:9000/testbucket/0001-dsync.patch
https://play.minio.io:9000/testbucket/filename.txt
https://play.minio.io:9000/testbucket/mc
https://play.minio.io:9000/testbucket/my-objectname
https://play.minio.io:9000/testbucket/test1
https://play.minio.io:9000/testbucket/test1.txt
https://play.minio.io:9000/testbucket/test2.txt
https://play.minio.io:9000/testbucket/1/ldap/client.go
https://play.minio.io:9000/testbucket/1/ldap/example.go
https://play.minio.io:9000/testbucket/accounts/1.original.jpg
https://play.minio.io:9000/testbucket/accounts/2.original.jpg
https://play.minio.io:9000/testbucket/accounts/c4a3ec89-3adf-40dc-822f-2d5ca8e22e32.original.jpg
https://play.minio.io:9000/testbucket/documents/1_files/issue
https://play.minio.io:9000/testbucket/documents/2_files/issue
https://play.minio.io:9000/testbucket/resumes/4.large.png
https://play.minio.io:9000/testbucket/resumes/4.original.pdf
https://play.minio.io:9000/testbucket/resumes/4.thumb.png

What is the equivalent API call to this CLI command that will provide me the same output?

I am using minio java SDK version 8.3.0 and the API methods available in io.minio.messages.Item class doesn't seem to provide a property that would give me the absolute URL to itself (object)

Any pointers?

You can use list objects api and presigned get url.
A sample web implementation can be found in
https://github.com/prakashsvmx/minio-js-web-browser-example/blob/f0513c63c2d3b51f20467387556ad7c91cd93c78/src/ListObjects.js#L37

Also you can make the bucket public using policy so you can directly access the objcets

You can use list objects api and presigned get url.
A sample web implementation can be found in
https://github.com/prakashsvmx/minio-js-web-browser-example/blob/f0513c63c2d3b51f20467387556ad7c91cd93c78/src/ListObjects.js#L37

Also you can make the bucket public using policy so you can directly access the objcets

This is useful

Had to use mc policy set download alias/bucket/

note the set after policy

@CanRau

some built in policies are provided for ease of use and convenience.

Please check
https://docs.min.io/docs/javascript-client-api-reference#setBucketPolicy

you could export the policy using mc and use/modify or create a new policy and apply it as per your requirements.

# Set the policy on a bucket
$ mc policy set download local/test-bucket
Access permission for `local/test-bucket` is set to `download`

# get the policy json
$ mc policy get-json local/test-bucket


# Pass this via API