Ajhar Shaikh
Ajhar Shaikh

Reputation: 1124

Rackspace cloudfiles generate temp URL with overriding file name in Java?

I am working with rackspace cloudfiles java api. So far,I have managed to write code for generating temp URL to download file, with java api by rackspace using example provided here.

https://github.com/jclouds/jclouds-examples/blob/master/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/GenerateTempURL.java

I can also see in rackspace api documentation which confirms me there is possibilities to override file name using temp URL while download file.

http://docs.rackspace.com/files/api/v1/cf-devguide/content/TempURL_File_Name_Overrides-d1e213.html

Unfortunately, I am unable to find any method in those java api to achieve same, can anybody help me with this?

Upvotes: 0

Views: 587

Answers (3)

Ajhar Shaikh
Ajhar Shaikh

Reputation: 1124

Well, this is were I am ending up it with

RegionScopedBlobStoreContext blobStoreContext = ContextBuilder
            .newBuilder(RS_PROVIDER)
            .credentials(RS_USER_NAME, RS_API_KEY)
            .buildView(RegionScopedBlobStoreContext.class);

HttpRequest request = blobStoreContext.signerInRegion(regionCode)
        .signGetBlob(rackspaceCfContainer.getContainerName(),
                rackspaceCfDocHistory.getFileName(),
                RS_TEMP_URL_EXP_DUR);

String fileNameParam = "&filename=" + aliasFileName;

String fileNameURLFrag = null;
try {
    if (fileNameParam != null)
        fileNameURLFrag = UriUtils.encodeFragment(fileNameParam, "UTF-8");
} catch (UnsupportedEncodingException e) {
}

String url = request.getEndpoint().toString();

StringBuffer urlBuffer = new StringBuffer(url);
if (fileNameURLFrag != null)
    urlBuffer.append(fileNameURLFrag);

String finalURL = urlBuffer.toString();

This is simply a workaround and not a solution I was looking for, but still it work and we can resolve the issue. Here, I am just appending auto generated URL by an encoded query parameter.

Upvotes: 1

zacksh
zacksh

Reputation: 316

If I understand this correctly, this is not done during object creation but only when the object is requested. The URL param just causes the service to override a header in the response that browsers understand. The actual filename is not modified.

Specifically under http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html

See 19.5.1 Content-Disposition

Upvotes: 0

Andrew Gaul
Andrew Gaul

Reputation: 2402

Can you set the content disposition during object creation? This will allow all subsequent object fetches, including via temporary signed URLs, to use a custom file name.

Upvotes: 0

Related Questions