我使用了 AWS 开发工具包,它非常适合我。这是我为将本地驱动器上的文件上传到海象而编写的示例代码。希望你觉得它有用。
AmazonS3 s3 = new AmazonS3Client(new AWSCredentials() {
@Override
public String getAWSSecretKey() {
return "G0WewmHyE5KYaGcVWvSAQrsBsPnJb2qQOPIIc74h";
}
@Override
public String getAWSAccessKeyId() {
return "4OFCOBFGPGVINNR7H6TMG";
}
});
s3.setEndpoint("http://10.14.99.97:8773/services/Walrus/");
byte[] bytes = convertToByteArray("/home/harshit/Desktop/poster.jpg"); // function written by me for extracting byte stream out of a local file
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
PutObjectRequest request = new PutObjectRequest("skg", "foo.jpg", is, metaData);
s3.putObject(request);