문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top