سؤال

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