Content-Type of an object specifies the type of the object and determines the method and decoding type used to read the object.
In some cases, you must specify Content-Type for the object that you want to upload. Otherwise, the object cannot be read by using the specified method. If you do not specify Content-Type when you use OSS SDK for Android to upload an object, OSS SDK for Android automatically specifies Content-Type based on the suffix of the object.
Sample code
The following sample code provides an example on how to specify Content-Type of an object:
// Construct an upload request.
// Specify the name of the bucket, the full path of the object, and the full path of the local file. In this example, the name of the bucket is examplebucket, the full path of the object is exampledir/exampleobject.txt, and the full path of the local file is /storage/emulated/0/oss/examplefile.txt.
// The full path of the object cannot contain the bucket name.
PutObjectRequest put = new PutObjectRequest("examplebucket", "exampledir/exampleobject.txt", "/storage/emulated/0/oss/examplefile.txt");
ObjectMetadata metadata = new ObjectMetadata();
// Specify Content-Type.
metadata.setContentType("application/octet-stream");
// Configure user metadata.
metadata.addUserMetadata("x-oss-meta-name1", "value1");
put.setMetadata(metadata);
OSSAsyncTask task = oss.asyncPutObject(put, new OSSCompletedCallback<PutObjectRequest, PutObjectResult>() {
...
});