我在将图像上传到亚马逊时遇到问题 s3
Android 中的服务器。
我创建了一个存储桶,每次都需要将图像发布到该存储桶中。当我第一次尝试将图像发布到该存储桶时,它可以从下次发布到单词,并显示如下消息:
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
我可以在单个存储桶中上传图像吗?我尝试过
s3Client.createBucket(Constants.getPictureBucket());
// Content type is determined by file extension.
PutObjectRequest por = new PutObjectRequest(Constants.getPictureBucket(), Constants.PICTURE_NAME, new java.io.File(filePath));
s3Client.putObject(por);
有人可以帮助我吗?
最佳答案
我假设您知道如何从图库中获取图像。您可以通过几个步骤将图像上传到服务器中。请按照以下步骤操作,
1.从图库中获取图像。
2.将图像转换为Bitmap并将其压缩为您想要的格式。
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.icon);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
3.将 Bitmap 转换为 byte[] 。
byte [] byte_arr = stream.toByteArray();
String image_str = Base64.encodeBytes(byte_arr);
4.然后使用Http Post
请求发送。
我指的链接是this .
这是满足您确切需求的链接http://blog.3dmick.com/2012/06/android-app-for-uploading-images-on-server/
关于android - 如何在android中将图库或捕获的图像上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18635253/