简体   繁体   English

在Rackspace云文件API中获取对象的链接

[英]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. 我正在使用Java jclouds API访问我的Rackspace云文件帐户。

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). (通过右键单击对象,我可以从Rackspace控制面板中看到这些公共链接-有4种类型:HTTP,HTTPS,Streaming,iOS Streaming)。

The closest I can get is by using object.getInfo() to get the object's metadata. 我可以得到的最接近的方法是使用object.getInfo()获取对象的元数据。 This includes a URI, but this doesn't resemble the public links I find from within the control panel. 这包括一个URI,但这与我在控制面板中找到的公共链接不一样。

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. 首先,我应该从对象中获取对象容器的公共URI。

Then I use a CloudFilesClient object. 然后,我使用CloudFilesClient对象。 On the container I need to use getCDNMetadata("containername").getCDNUri() 在容器上,我需要使用getCDNMetadata("containername").getCDNUri()

Here is more information and some sample code to get the specific file CDN address. 这是更多信息和一些示例代码,用于获取特定的文件CDN地址。 For more details you can checkout the Java guide: https://developer.rackspace.com/docs/cloud-files/quickstart/?lang=java 有关更多详细信息,您可以查看Java指南: https : //developer.rackspace.com/docs/cloud-files/quickstart/?lang= java

First get the cloud files api: 首先获取云文件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: 现在,通过该CDNContainer,您可以获取所需的特定网址:

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

This will get you the base URI for the container. 这将为您提供容器的基本URI。 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. 现在,要获取特定文件的最终地址,您需要在地址末尾附加/{"your_file_name.extension“} For example if my base URI was converted to a URL then to a String it may look like: 例如,如果我的基本URI转换为URL,然后转换为String,则它可能类似于:

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

From here I can get a file with the name example.mp4 with the following address: 从这里我可以得到一个名为example.mp4的文件,其地址如下:

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

This all assumes that you have already enabled CDN on the container. 所有这些都假定您已经在容器上启用了CDN。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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