I want to upload image using Cloudinary server in my chat application,I have read the documentation regarding the uploading images ,I have also registered my myself on this Cloudinary server and get the api key ,secret key ,cloud name and environment . Below is my code for uloading image .
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.