gpt4 book ai didi

android - 如何将图像从android上传到Cloudinary?

转载 作者:太空狗 更新时间:2023-10-29 14:44:05 25 4
gpt4 key购买 nike

基本上我想做的就是从图库中选择一张图片,然后将同一张图片上传到我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com