【问题标题】:how can i upload images using cloudinary in android我如何在 android 中使用 cloudinary 上传图像
【发布时间】:2023-03-16 12:15:01
【问题描述】:

我想在我的聊天应用程序中使用 Cloudinary 服务器上传图片,我已经阅读了关于上传图片的文档,我也在这个 Cloudinary 服务器上注册了我自己并获得了 api 密钥、密钥、云名称和环境。 下面是我上传图片的代码。

    public class ImageUpload extends Activity
    {
        private static boolean first = true;
    private ProgressDialog dialog = null;
        Cloudinary cloudinary;

        JSONObject Result;
            String file_path = "";
        File file;
        Button btnupload;
        FileInputStream fileInputStream;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.imageupload);
                 Intent i = getIntent();
                btnupload = (Button)findViewById(R.id.btn_upload);
                file_path = "/storage/emulated/0/Contacts_Cover/crop_ContactPhoto-IMG_20150814_152743.jpg";
        HashMap config = new HashMap();
                config.put("cloud_name", "chatgeeta");
                config.put("api_key", "255663733636595");//I have changed the key and secret
                config.put("api_secret", "5Upmclme1ydaTWBi7_COU7uIns0");
                cloudinary = new Cloudinary(config);
              TextView textView = (TextView) findViewById(R.id.textView1);
                textView.setText(file_path);
                file = new File(file_path);
                try {
                     fileInputStream = new FileInputStream(file);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
             }
          public class Upload extends AsyncTask<String, Void, String>
        {
            private Cloudinary mCloudinary;

            public Upload( Cloudinary cloudinary ) {
                super();
                mCloudinary = cloudinary;
            }
            @Override
            protected String doInBackground(String... params) {
                String response ="";
                try
                {
                    Result =  (JSONObject) mCloudinary.uploader().upload(fileInputStream, Cloudinary.emptyMap());
                }
                catch(Exception ex)
                {
                    ex.printStackTrace();
                }
                return response;
            }

            @Override
            protected void onPostExecute(String result) {
                 TextView textView = (TextView) findViewById(R.id.textView1);
                    textView.setText("file uploaded");
                super.onPostExecute(result);
            }}
        public void upload(View view)
 {
            new Upload( cloudinary ).execute();
    }}

    When i execute above code then i got "Caused by java.lang.NoClassDefFoundError:org.apache.commons.lang.StringUtils" as error.     

【问题讨论】:

    标签: android cloudinary


    【解决方案1】:

    首先,请注意,强烈不建议公开透露您的 Cloudinary 凭据(尤其是您的 API_SECRET),因为它可能会损坏您现有的内容。您可以通过account settings page 消除这些密钥对并生成一个新的。

    此外,您看到的问题似乎源于您的依赖项配置。看到这个帖子:NoClassDefFoundError : org.apache.commons.lang.StringUtils

    【讨论】:

      猜你喜欢
      • 2017-08-04
      • 2016-01-13
      • 2018-07-29
      • 2019-09-21
      • 2020-02-16
      • 2017-09-15
      • 2018-03-15
      • 2020-04-07
      • 2020-07-07
      相关资源
      最近更新 更多