如何在android中使用cloudinary上传图像
我想在我的聊天应用程序中使用Cloudinary服务器上传图像,我已经阅读了关于上传图像的文档,我也在这个Cloudinary服务器上注册了我自己,并获得了api密钥、密钥、云名称和环境。 下面是我用来读取图像的代码如何在android中使用cloudinary上传图像,android,cloudinary,Android,Cloudinary,我想在我的聊天应用程序中使用Cloudinary服务器上传图像,我已经阅读了关于上传图像的文档,我也在这个Cloudinary服务器上注册了我自己,并获得了api密钥、密钥、云名称和环境。 下面是我用来读取图像的代码 public class ImageUpload extends Activity { private static boolean first = true; private ProgressDialog dialog = null;
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.
公共类ImageUpload扩展活动
{
private static boolean first=true;
private ProgressDialog=null;
阴云密布;
JSONObject结果;
字符串文件_path=“”;
文件;
按钮btnupload;
FileInputStream FileInputStream;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.imageupload);
Intent i=getIntent();
btnupload=(按钮)findviewbyd(R.id.btn_上传);
文件路径=“/storage/simulated/0/Contacts\u Cover/crop\u ContactPhoto-IMG\u 20150814\u 152743.jpg”;
HashMap config=newhashmap();
config.put(“cloud_name”、“chatgeeta”);
config.put(“api_key”,“255663733636595”);//我已经更改了密钥和密码
配置放置(“api_机密”、“5Upmclme1ydaTWBi7_COU7uIns0”);
cloudinary=新的cloudinary(配置);
TextView TextView=(TextView)findViewById(R.id.textView1);
setText(文件路径);
文件=新文件(文件路径);
试一试{
fileInputStream=新的fileInputStream(文件);
}catch(filenotfounde异常){
e、 printStackTrace();
}
}
公共类上载任务
{
private Cloudinary mCloudinary;
公共上传(Cloudinary Cloudinary){
超级();
mCloudinary=cloudinary;
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
字符串响应=”;
尝试
{
结果=(JSONObject)mCloudinary.uploader().upload(fileInputStream,Cloudinary.emptyMap());
}
捕获(例外情况除外)
{
例如printStackTrace();
}
返回响应;
}
@凌驾
受保护的void onPostExecute(字符串结果){
TextView TextView=(TextView)findViewById(R.id.textView1);
setText(“上传的文件”);
super.onPostExecute(结果);
}}
公共作废上传(查看)
{
新上传(cloudinary.execute();
}}
当我执行上述代码时,我得到了“由java.lang.NoClassDefFoundError:org.apache.commons.lang.StringUtils引起的”作为错误。
首先,请注意,强烈建议不要公开披露您的Cloudinary凭据(尤其是您的API_SECRET
),因为它可能会损坏您现有的内容。您可以消除这些密钥对,并通过您的
此外,您看到的问题似乎起源于您的依赖项配置。查看此线程:首先,请注意,强烈建议不要公开披露您的Cloudinary凭据(尤其是您的
API_SECRET
),因为它可能会损坏您现有的内容。您可以消除这些密钥对,并通过您的
此外,您看到的问题似乎起源于您的依赖项配置。请参阅此线程: