作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
基本上我想做的就是从图库中选择一张图片,然后将同一张图片上传到我的 Cloudinary 帐户,我看过 Cloudinary 的文档,但我不太了解它是如何工作的,因此不知道如何在我的代码中实现它。
这是我获取信息的链接,以备不时之需... https://github.com/cloudinary/cloudinary_java/tree/master/cloudinary-android
这就是我目前所拥有的......
upload_image.class
public class edit_profile_activity extends AppCompatActivity
{
private static int RESULT_LOAD_IMG = 1;
String imgDecodableString;
public void loadImagefromGallery(View view)
{
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
try
{
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != data)
{
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
ImageView imgView = (ImageView) findViewById(R.id.circleImageView );
imgView.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString));
} else {
Toast.makeText(this, "You haven't picked Image",Toast.LENGTH_LONG).show();
}
} catch (Exception e)
{
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG) .show();
}
}
}
任何帮助将不胜感激
最佳答案
你可以为 Cloudinary 使用这个简单的上传功能:
Cloudinary cloudinary = new Cloudinary(Constants.CLOUDINARY_URL);
try {
FileInputStream is = new FileInputStream(new File(filePath));
Uploader uploader = cloudinary.uploader();
Map map = uploader.upload(is, new HashMap());
return map;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
这里有进一步的解释:The order is like this: Take picture->save to file->upload to cloudinary
关于android - 如何将图像从android上传到Cloudinary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42778387/
我是一名优秀的程序员,十分优秀!