import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.volcengine.tos.TOSV2;
import com.volcengine.tos.TOSV2ClientBuilder;
import com.volcengine.tos.TosException;
import com.volcengine.tos.comm.common.ACLType;
import com.volcengine.tos.comm.common.StorageClassType;
import com.volcengine.tos.model.object.ObjectMetaRequestOptions;
import com.volcengine.tos.model.object.PutObjectBasicInput;
import com.volcengine.tos.model.object.PutObjectInput;
import com.volcengine.tos.model.object.PutObjectOutput;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
public class PutObjectWithMetaExample extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
String endpoint = "your endpoint";
String region = "your region";
String accessKey = "your access key";
String secretKey = "your secret key";
String securityToken = "your security token";
String bucketName = "your bucket name";
String objectKey = "your object key";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey, securityToken);
Thread tosThread = new Thread(new Runnable() {
String data = "1234567890abcdefghijklmnopqrstuvwxyz~!@#$%^&*()_+<>?,./ :'1234567890abcdefghijklmnopqrstuvwxyz~!@#$%^&*()_+<>?,./ :'";
ByteArrayInputStream stream = new ByteArrayInputStream(data.getBytes());
ObjectMetaRequestOptions options = new ObjectMetaRequestOptions();
options.setAclType(ACLType.ACL_PRIVATE);
options.setStorageClass(StorageClassType.STORAGE_CLASS_STANDARD);
options.setContentType("application/json");
options.setContentLanguage("en");
options.setContentDisposition("attachment;filename=download.txt");
options.setCacheControl("max-age=600");
options.setContentMD5("yjtlyPoGKxvDj+QOPocqjg==");
options.setServerSideEncryption("AES256");
Map<String, String> custom = new HashMap<>();
custom.put("name", "volc_user");
options.setCustomMetadata(custom);
PutObjectBasicInput basicInput = new PutObjectBasicInput().setBucket(bucketName).setKey(objectKey).setOptions(options);
PutObjectInput putObjectInput = new PutObjectInput().setPutObjectBasicInput(basicInput).setContent(stream);
PutObjectOutput output = tos.putObject(putObjectInput);
Log.i("putObject", "putObject succeed, object's etag is " + output.getEtag());
Log.i("putObject", "putObject succeed, object's crc64 is " + output.getHashCrc64ecma());
} catch (TosException e) {
Log.e("TosException", "putObject failed");