android - 如何在android中将图库或捕获的图像上传到服务器

标签 android image

我在将图像上传到亚马逊时遇到问题 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/

相关文章:

android - 如何在 AlertDialog multiChoiceItems 中获取所有选定的索引

css - 使用CSS使两个透明图像重叠

swift - 图像全屏查看 - 需要缩放

android - Google maps api v2 Android 未在 locationListener 上更新

android - 在带有 Parse.com 后端的 Android 中使用 Twitters API

android - 如何过滤和执行特定的Gradle任务?

c# - 通过指定高度或宽度在 ASP.NET C# 中按比例调整图像大小

python - 使用 Pillow 创建隐写隐藏图像

css - linux下如何给图片添加底框和文字

android - Git 实验分支还是单独的实验存储库?