camera - upload captured image to cloudinary in android -
i want upload captured picture image cloudinary have error in statment :
cloudinary.uploader().upload(is, cloudinary.emptymap());
java.lang.noclassdeffounderror: org.apache.commons.lang.stringutils
i want ask should pass @ define name of pic
first the uri , convert string path convert real path inputstream so, pass cloudinary uploading statement
private static final int camera_request = 1888; private imageview imageview; textview tv; string s="aa"; map config = new hashmap(); cloudinary cloudinary; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.camera); config.put("cloud_name", "dkepfkeuu"); config.put("api_key", "key"); config.put("api_secret", "secret"); cloudinary = new cloudinary(config); tv=(textview)findviewbyid(r.id.textview); this.imageview = (imageview)this.findviewbyid(r.id.imageview1); button photobutton = (button) this.findviewbyid(r.id.button1); photobutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent cameraintent = new intent(android.provider.mediastore.action_image_capture); startactivityforresult(cameraintent, camera_request); } }); } bitmap photo; inputstream is; protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == camera_request && resultcode == result_ok) { photo = (bitmap) data.getextras().get("data"); imageview.setimagebitmap(photo); s= data.getdatastring(); toast.maketext(this, "image saved to:\n" + data.getdata(), toast.length_long).show(); uri uripath= data.getdata(); string uri = getrealpathfromuri( uripath); try { = new fileinputstream(uri); } catch (filenotfoundexception e) { e.printstacktrace(); } toast.maketext(this, "uri:\n" + uri, toast.length_long).show(); tv.settext(s+"---"+uri); try { cloudinary.uploader().upload(is, cloudinary.emptymap()); } catch (ioexception e) { e.printstacktrace(); } } } public string getrealpathfromuri(uri contenturi) { cursor cursor = null; try { string[] proj = { mediastore.images.media.data }; cursor =getcontentresolver().query(contenturi, proj, null, null, null); int column_index = cursor.getcolumnindexorthrow(mediastore.images.media.data); cursor.movetofirst(); return cursor.getstring(column_index); } { if (cursor != null) { cursor.close(); } } }
}
you don't need convert uri string, doing following in upload code:
inputstream in = getcontentresolver().openinputstream(profileimageuri); cloudinaryclient.upload(in, profileimagename);
cloudinaryclient:
public static void upload(final inputstream inputstream, final string publicid) { final map<string, string> options = new hashmap<>(); options.put("public_id", publicid); runnable runnable = new runnable() { @override public void run() { try { cloudinary.uploader().upload(inputstream, options); } catch (ioexception e) { //todo: better error handling when image uploading fails e.printstacktrace(); } } }; new thread(runnable).start(); }
note: can pass null options, use specifiy name image uploading.
Comments
Post a Comment