我想将图像上传到android中的amazon s3存储桶.
我没有得到任何错误,但只是没有工作可以有人帮助我吗?
我找不到任何关于此的好例子或问题.
我将图像分配给’文件images3′
images3 = new File(uri.getPath());
public void addEventToDB(){
Thread thread = new Thread()
{
@Override
public void run() {
try {
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getActivity().getApplicationContext(),// get the context for the current activity
"...","us-east-1:...","arn:aws:iam::...:role/Cognito_WitpaAuth_DefaultRole",Regions.US_EAST_1
);
String bucket_name = "witpa";
String key = "images.jpeg";
TransferManager transferManager = new TransferManager(credentialsProvider);
transferManager.upload(bucket_name,key,images3);
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
}
我创建了我的存储桶,在我设置的权限中,每个人都可以写和读.
在amazon cognito中,我只是将一切都保留为默认值.
谁知道我怎么能让这个工作?
最佳答案
试试这个吧.因为我遇到了同样的问题.
原文链接:https://www.f2er.com/android/431175.html我已使用以下代码修复.
ObjectMetadata Metadata = new ObjectMetadata();
Metadata.setContentEncoding("UTF-8");
size = inputStream.available();
Metadata.setContentLength(size);
TransferManager transferManager = new TransferManager(credentialsProvider);
Upload upload = transferManager.upload(bucket_name,images3,Metadata);
upload.waitForCompletion();