rackspace-cloudjcloudsrackspace-cloudfiles

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?


Solution

  • 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.