你好朋友我想在亚马逊服务器上传文件或.mobileconfig,但我无法在亚马逊服务器上传文件,我可以在亚马逊服务器上传图像。请朋友帮助我如何在 android 的亚马逊服务器中上传文件。
问问题
185 次
1 回答
0
终于得到了答案
// Put the image data into S3.
try {
String bucketw = getPictureBucket();
Log.d("ddddd", "bucketw : " + bucketw);
// Content type is determined by file extension.
// PutObjectRequest por = new PutObjectRequest(
// getPictureBucket(), Constants.PICTURE_NAME,
// new java.io.File(filePath));
System.out.println(finammane);
//
String bucket = "vpnme";
File file = new File("/mnt/sdcard/vp.txt");
InputStream in = new FileInputStream("/mnt/sdcard/vp.txt");
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024]; // you can configure the buffer
// size
while (in.read(buffer) != -1)
out.write(buffer); // copy streams
byte[] result2 = out.toByteArray();
Long contentLength = Long.valueOf(result2.length);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(contentLength);
PutObjectRequest por = new PutObjectRequest(getPictureBucket(),
finammane, new java.io.File("/mnt/sdcard/vp.txt")).withCannedAcl(
CannedAccessControlList.PublicRead).withMetadata(
metadata);
s3Client.putObject(por);
// Just set your directory
// PutObjectRequest request = new
// PutObjectRequest("my-unique-name",
// "vpnme/" + Constants.PICTURE_BUCKET, file).withCannedAcl(
// CannedAccessControlList.PublicRead).withMetadata(metadata);
// s3Client.putObject(request);
in.close();
// buffer.
} catch (Exception exception) {
System.out.println("eeee" + exception);
Log.d("e", "ee " + exception.getMessage());
result.setErrorMessage(exception.getMessage());
}
于 2013-06-18T09:45:02.897 回答