android upload image to amazon storage with image path -


i want upload image using it's file path. of tutorial have followed regarding upload image amazon, there select image option(image chooser galary). need that:

but want skip step. know image path , name. suppose have image in directory in device. when user click upload photo button, start uploading. want skip select image option. how can upload image amazon storage image path instead of selecting image (intent image/*)?

so in short wanting use file path directly instead of select image option upload image in amazon.

any appreciated. in advance.

edited:

here activity:

public class submitactivity extends activity {  button submit; imageview thumbnailimage; private amazons3client s3client = new amazons3client(         new basicawscredentials(constants.access_key_id,                 constants.secret_key));  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     // getactionbar().setdisplayshowtitleenabled(false);     this.requestwindowfeature(window.feature_no_title);     s3client.setregion(region.getregion(regions.us_west_2));     setcontentview(r.layout.submit);      submit = (button) findviewbyid(r.id.buttonsubmit);     submit.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub              uri selectedimage = uri.parse(environment                     .getexternalstoragedirectory().tostring()                     + file.separator + "cubicasa.jpg");             new s3putobjecttask().execute(selectedimage);         }     });     thumbnailimage = (imageview) findviewbyid(r.id.thumbimg);      byte[] imagedata = null;      try {          final int thumbnail_size = 150;         // inputstream is=getassets().open("apple-android-battle.jpg");         fileinputstream fis = new fileinputstream(environment                 .getexternalstoragedirectory().tostring()                 + file.separator                 + "cubicasa.jpg");         bitmap imagebitmap = bitmapfactory.decodestream(fis);          float width = new float(imagebitmap.getwidth());         float height = new float(imagebitmap.getheight());         float ratio = width / height;         imagebitmap = bitmap.createscaledbitmap(imagebitmap,                 (int) (thumbnail_size * ratio), thumbnail_size, false);          bytearrayoutputstream baos = new bytearrayoutputstream();         imagebitmap.compress(bitmap.compressformat.jpeg, 100, baos);         imagedata = baos.tobytearray();         thumbnailimage.setimagebitmap(imagebitmap);     } catch (exception ex) {      }  }  private class s3putobjecttask extends asynctask<uri, void, s3taskresult> {      progressdialog dialog;      protected void onpreexecute() {         dialog = new progressdialog(submitactivity.this);         dialog.setmessage(submitactivity.this.getstring(r.string.uploading));         dialog.setcancelable(false);         dialog.show();     }      protected s3taskresult doinbackground(uri... uris) {          if (uris == null || uris.length != 1) {             return null;         }          // file location of image selected.         uri selectedimage = uris[0];          contentresolver resolver = getcontentresolver();         string filesizecolumn[] = { openablecolumns.size };          cursor cursor = resolver.query(selectedimage, filesizecolumn, null,                 null, null);          cursor.movetofirst();          int sizeindex = cursor.getcolumnindex(openablecolumns.size);         // if size unknown, value stored null. since         // int can't         // null in java, behavior implementation-specific,         // fancy         // term "unpredictable". rule, check if it's null before         // assigning         // int. happen often: storage api allows         // remote         // files, size might not locally known.         string size = null;         if (!cursor.isnull(sizeindex)) {             // technically column stores int, cursor.getstring             //             // conversion automatically.             size = cursor.getstring(sizeindex);         }          cursor.close();          objectmetadata metadata = new objectmetadata();         metadata.setcontenttype(resolver.gettype(selectedimage));         if (size != null) {             metadata.setcontentlength(long.parselong(size));         }          s3taskresult result = new s3taskresult();          // put image data s3.         try {             s3client.createbucket(constants.getpicturebucket());              putobjectrequest por = new putobjectrequest(                     constants.getpicturebucket(), constants.picture_name,                     resolver.openinputstream(selectedimage), metadata);             s3client.putobject(por);         } catch (exception exception) {              result.seterrormessage(exception.getmessage());         }          return result;     }      protected void onpostexecute(s3taskresult result) {          dialog.dismiss();          if (result.geterrormessage() != null) {              displayerroralert(                     submitactivity.this                             .getstring(r.string.upload_failure_title),                     result.geterrormessage());         }     } }  protected void displayerroralert(string title, string message) {      alertdialog.builder confirm = new alertdialog.builder(this);     confirm.settitle(title);     confirm.setmessage(message);      confirm.setnegativebutton(             submitactivity.this.getstring(r.string.ok),             new dialoginterface.onclicklistener() {                  public void onclick(dialoginterface dialog, int which) {                      submitactivity.this.finish();                 }             });      confirm.show().show(); }  private class s3taskresult {     string errormessage = null;     uri uri = null;      public string geterrormessage() {         return errormessage;     }      public void seterrormessage(string errormessage) {         this.errormessage = errormessage;     }      public uri geturi() {         return uri;     }      public void seturi(uri uri) {         this.uri = uri;     } }  } 

here log cat error:

enter image description here

enter image description here

try this:

uri uriimg =uri.parse(environment.getexternalstoragedirectory().getpath() + "/images/img1.jpg");        putobjectrequest por = new putobjectrequest( constants.getpicturebucket(),            constants.picture_name, new java.io.file( uriimg) );       s3client.putobject( por );   

i hpoe help:


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -