문제

I'm using Rackspace's Cloud Files product and I've been successfully putting files to my containers, however, during testing I found that files did not have a set Content-Type.

I've looked high and low for examples on how to set content type with the Java SDK, but no luck.

What I have tried:

Map<String, String> metaData = new HashMap<String, String>();
metaData.put("mime-type", content_type);
// or metaData.put("Content-Type", content_type);

Blob blob = storage.blobBuilder(file.getName())
    .payload(file).userMetadata(metaData).build();

storage.putBlob(container, blob);

Any help would be appreciated.

도움이 되었습니까?

해결책 2

Solved it! The problem was that it's not Metadata and that BlobBuilder.PayloadBlobBuilder has a method called contentType where you can set the String value.

Blob blob = storage.blobBuilder(file.getName())
    .payload(file).contentType(content_type).build();
storage.putBlob(container, blob);

다른 팁

CloudFiles will actually set the content type for you so there's no need for content type guessing in your code. The trick is to make sure jclouds sends no content type.

Blob blob = storage.blobBuilder(filename)
    .payload(file)
    .contentType("") // allows Cloud Files to determine the content type
    .build();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top