Rackspace cloud files return "application/unknown" as mime-type when uploaded with Jclouds

681 views Asked by At

Basically I have this code which uploads javascripts and other content to Rackspace using Jclouds:

SwiftObject obj = cloudFilesClient.newSwiftObject();
obj.getInfo().setName(name);
obj.getInfo().setContentType(contentType);
obj.setPayload(payloadFile);
cloudFilesClient.putObject(container, obj);

I noticed that Chrome complains about scripts being transferred with text/plain and so set out to investigate. curl -I report instead: Content-Type: application/unknown.

I've Googled a lot and tried to find some clues, and I've tried:

  • not setting content type at all
  • setting empty string (found some rumour about that somewhere)
  • setting to application/javascript (correct)
  • setting to text/javascript (wrong, but common)
  • obj.getAllHeaders().put("Content-Type", contentType);

When we used to upload with basic HTTP before, this just worked without setting anything manually at all.

1

There are 1 answers

2
Stoffe On BEST ANSWER

Finally finally managed to figure it out by digging in the source code - this works:

FilePayload payload = new FilePayload(uploadableFile.localPath.toFile());
payload.getContentMetadata().setContentType(uploadableFile.contentType);
obj.setPayload(payload);

In case anyone else is looking for this in the future, posting Q&A.