简体   繁体   中英

Getting an object's links in Rackspace cloud files API

I am using the Java jclouds API for access to my Rackspace cloud files account.

I can create and list containers, and upload objects, but I can't figure out how to get the public links for an uploaded object. (I can see these public links from within the Rackspace control panel, by right-clicking on the object - there are 4 types: HTTP, HTTPS, Streaming, iOS Streaming).

The closest I can get is by using object.getInfo() to get the object's metadata. This includes a URI, but this doesn't resemble the public links I find from within the control panel.

Anyone know what I'm doing wrong?

I figured it out...

First, I should get the public URI of the object's container, not from the object.

Then I use a CloudFilesClient object. On the container I need to use getCDNMetadata("containername").getCDNUri()

Here is more information and some sample code to get the specific file CDN address. For more details you can checkout the Java guide: https://developer.rackspace.com/docs/cloud-files/quickstart/?lang=java

First get the cloud files api:

    CloudFilesApi cloudFilesApi = ContextBuilder.newBuilder("rackspace-cloudfiles-us")
        .credentials("{username}", "{apiKey}")
        .buildApi(CloudFilesApi.class);

From there you can query the container:

    CDNApi cdnApi = cloudFilesApi.getCDNApi("{region}");
    CDNContainer cdnContainer = cdnApi.get("{containerName}");

Now with that CDNContainer you can get the specific web address that you need:

    URI httpURI = cdnContainer.getUri();
    URI httpsURI = cdnContainer.getSslUri();

This will get you the base URI for the container. Now to get the final address for your specific file you will need to append /{"your_file_name.extension"} to the end of the address. For example if my base URI was converted to a URL then to a String it may look like:

    http://123456asdf-qwert987653.rackcdn.com/

From here I can get a file with the name example.mp4 with the following address:

    http://123456asdf-qwert987653.rackcdn.com/example.mp4

This all assumes that you have already enabled CDN on the container.

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