javarestrackspaceopenstack-swiftrackspace-cloudfiles

How can I specify optional parameters when copy files in Openstack Swift using Java API


I'm using Rackspace Cloud Files (Openstack Swift) in Java application, and have the following scenario: I upload files to a container (from web app, through my java rest backend) to a temporary location in rackspace container, and than, when some event happens (user confirms form saving), I need to move those files to a persistent location in that (the same) container.

I need those files to be downloaded then from my web app, so when uploading a file I specify header:

Content-Disposition=attachment;filename=thefilename.xxx

Also I specify header for files in my temporal storage X-Delete-At, so they could de automatically deleted if user doesn't save the form.

For copying file I use method from ObjectApi:

boolean copy(String destinationObject, String sourceContainer, String sourceObject)

It copies file content, file metadata, but doesn't copy Content-Disposition. It seems that there is no way to set it after copying.

The problem is that Cloud Files REST API allows to specify Content-Disposition header for copied target file, but Java API doesn't. I wonder if there a way to extend that API or call that service with required header somehow alternatively.


Solution

  • What helped me to solve the problem, is to upgrade jcouds libraries to v. 2.0.3.

    In this version ObjectApi contains parameterized copy() methods allowing to specify another headers for a copied file (sending X-Fresh-Metadata header).

    This is how I specify Content-Disposition header, and avoid copying X-Delete-At header:

    Map<String, String> contentMetadata = new HashMap<>();
    contentMetadata.put("Content-Type", "image/jpeg");
    contentMetadata.put("Content-Disposition", "attachment; filename=\"myfilename.jpg\"");
    objectApi.copy(toPath, containerName, fromPath, new HashMap<>(), contentMetadata, CopyOptions.NONE);