Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top