【发布时间】:2016-04-24 13:54:14
【问题描述】:
如何将图像上传到 Android 中的 Amazon s3 存储桶?。我有用于上传的密钥和访问密钥,但仍然无法执行。这是我的代码
protected String doInBackground(String... params) {
publishProgress("Sleeping..."); // Calls onProgressUpdate()
String date = (DateFormat.format("dd-MM-yyyy hh:mm:ss", new java.util.Date()).toString());
String ACCESS_KEY = "",
SECRET_KEY = "",
MY_BUCKET = "retailappimages",
OBJECT_KEY = unique_id+"-"+date;
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonS3 s3 = new AmazonS3Client(credentials);
java.security.Security.setProperty("networkaddress.cache.ttl", "60");
s3.setRegion(Region.getRegion(Regions.AP_SOUTHEAST_1));
s3.setEndpoint("https://s3-ap-southeast-1.amazonaws.com/");
Log.i("path", myUri.getPath());
TransferManager tx = new TransferManager(credentials);
myUpload = tx.upload(MY_BUCKET, OBJECT_KEY, new java.io.File(getBitmapUri(img_product).getPath()));
return resp;
}
【问题讨论】:
-
您应该提供更多信息。您尝试了哪些库?出了什么问题。
-
@CyberAleks...你能告诉我怎么做吗...如果你知道...因为我是 android 新手
-
您需要来自 Amazon 的库。阅读 s3 的开发者文档。
-
你有任何成功的代码吗?只需提供..
-
@Tinto Mathew:查看我的答案,该答案在我当前的项目中正常工作。