I have multiple image path (URI/String) how do i upload them to Amazon S3 -



I have multiple image path (URI/String) how do i upload them to Amazon S3 -

i have multiple image's path (uri / string). passing value " s3putobjecttask().execute(uri); " want upload images amazon s3. 1 help me how pass uris how upload multiple images.

similar log cat error found in android upload image amazon storage image path

thanks in advance

public class awsupload extends activity { private amazons3client s3client = new amazons3client( new basicawscredentials(constants.access_key_id, constants.secret_key)); string uri1a, uri2a, uri3a, uri4a; int i; private static final int photo_selected = 1; button b1; textview t1, t2, t3, t4; imageview iv1; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.inspectionreport); s3client.setregion(region.getregion(regions.us_west_2)); intent gettinguri = getintent(); uri1a = gettinguri.getstringextra("uri1"); uri2a = gettinguri.getstringextra("uri2"); uri3a = gettinguri.getstringextra("uri3"); uri4a = gettinguri.getstringextra("uri4"); b1 = (button) findviewbyid(r.id.button1); t1 = (textview) findviewbyid(r.id.textview1); t2 = (textview) findviewbyid(r.id.textview2); t3 = (textview) findviewbyid(r.id.textview3); t4 = (textview) findviewbyid(r.id.textview4); iv1 = (imageview) findviewbyid(r.id.imageview1); uri img1uri = uri.parse(uri1a); uri img2uri = uri.parse(uri2a); uri img3uri = uri.parse(uri3a); uri img4uri = uri.parse(uri4a); t1.settext(uri1a); t2.settext(uri2a); t3.settext(uri3a); t4.settext(uri4a); b1.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub (i = 1; <= 4; i++) { if (i == 1) { uri selectedimage1 = uri.parse(uri1a); new s3putobjecttask().execute(selectedimage1); } else if (i == 2) { uri selectedimage2 = uri.parse(uri2a); new s3putobjecttask().execute(selectedimage2); } else if (i == 3) { uri selectedimage3 = uri.parse(uri3a); new s3putobjecttask().execute(selectedimage3); } else if (i == 4) { uri selectedimage4 = uri.parse(uri4a); new s3putobjecttask().execute(selectedimage4); } else { intent returnintent = new intent(awsupload.this, productimagesss.class); startactivity(returnintent); } } } }); } // method automatically called image picker when image // selected. protected void onactivityresult(int requestcode, int resultcode, intent imagereturnedintent) { super.onactivityresult(requestcode, resultcode, imagereturnedintent); switch (requestcode) { case photo_selected: if (resultcode == result_ok) { uri selectedimage = imagereturnedintent.getdata(); new s3putobjecttask().execute(selectedimage); } } } // display alert message error or failure. protected void displayalert(string title, string message) { alertdialog.builder confirm = new alertdialog.builder(this); confirm.settitle(title); confirm.setmessage(message); confirm.setnegativebutton(awsupload.this.getstring(r.string.ok), new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { dialog.dismiss(); } }); confirm.show().show(); } protected void displayerroralert(string title, string message) { alertdialog.builder confirm = new alertdialog.builder(this); confirm.settitle(title); confirm.setmessage(message); confirm.setnegativebutton(awsupload.this.getstring(r.string.ok), new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { awsupload.this.finish(); } }); confirm.show().show(); } private class s3putobjecttask extends asynctask<uri, void, s3taskresult> { progressdialog dialog; protected void onpreexecute() { dialog = new progressdialog(awsupload.this); dialog.setmessage(awsupload.this.getstring(r.string.uploading)); dialog.setcancelable(false); dialog.show(); } protected s3taskresult doinbackground(uri... uris) { if (uris == null || uris.length != 1) { homecoming 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); string size = null; if (!cursor.isnull(sizeindex)) { 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(); // set image info s3. seek { // s3client.createbucket(constants.getpicturebucket()); putobjectrequest por = new putobjectrequest("mybucket", constants.picture_name, resolver.openinputstream(selectedimage), metadata); s3client.putobject(por); } grab (exception exception) { result.seterrormessage(exception.getmessage()); } homecoming result; } protected void onpostexecute(s3taskresult result) { dialog.dismiss(); if (result.geterrormessage() != null) { displayerroralert( awsupload.this.getstring(r.string.upload_failure_title), result.geterrormessage()); } } } private class s3taskresult { string errormessage = null; uri uri = null; public string geterrormessage() { homecoming errormessage; } public void seterrormessage(string errormessage) { this.errormessage = errormessage; } public uri geturi() { homecoming uri; } public void seturi(uri uri) { this.uri = uri; } }

}

my log cat:

e/androidruntime(18015): fatal exception: asynctask #3 e/androidruntime(18015): java.lang.runtimeexception: error occured while executing doinbackground() e/androidruntime(18015): @ android.os.asynctask$3.done(asynctask.java:299) e/androidruntime(18015): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:352) e/androidruntime(18015): @ java.util.concurrent.futuretask.setexception(futuretask.java:219) e/androidruntime(18015): @ java.util.concurrent.futuretask.run(futuretask.java:239) e/androidruntime(18015): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) e/androidruntime(18015): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) e/androidruntime(18015): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) e/androidruntime(18015): @ java.lang.thread.run(thread.java:838) e/androidruntime(18015): caused by: java.lang.nullpointerexception e/androidruntime(18015): @ com.cbazaarqc.awsupload$s3putobjecttask.doinbackground(awsupload.java:229) e/androidruntime(18015): @ com.cbazaarqc.awsupload$s3putobjecttask.doinbackground(awsupload.java:1) e/androidruntime(18015): @ android.os.asynctask$2.call(asynctask.java:287) e/androidruntime(18015): @ java.util.concurrent.futuretask.run(futuretask.java:234) e/androidruntime(18015): ... 4 more e/windowmanager(18015): activity com.cbazaarqc.awsupload has leaked window com.android.internal.policy.impl.phonewindow$decorview{420a16e0 v.e..... r......d 0,0-684,192} added here e/windowmanager(18015): android.view.windowleaked: activity com.cbazaarqc.awsupload has leaked window com.android.internal.policy.impl.phonewindow$decorview{420a16e0 v.e..... r......d 0,0-684,192} added here e/windowmanager(18015): @ android.view.viewrootimpl.<init>(viewrootimpl.java:409) e/windowmanager(18015): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:218) e/windowmanager(18015): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) e/windowmanager(18015): @ android.app.dialog.show(dialog.java:281) e/windowmanager(18015): @ com.cbazaarqc.awsupload$s3putobjecttask.onpreexecute(awsupload.java:211) e/windowmanager(18015): @ android.os.asynctask.executeonexecutor(asynctask.java:586) e/windowmanager(18015): @ android.os.asynctask.execute(asynctask.java:534) e/windowmanager(18015): @ com.cbazaarqc.awsupload.oncreate(awsupload.java:93) e/windowmanager(18015): @ android.app.activity.performcreate(activity.java:5122) e/windowmanager(18015): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1081) e/windowmanager(18015): @ android.app.activitythread.performlaunchactivity(activitythread.java:2270) e/windowmanager(18015): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2358) e/windowmanager(18015): @ android.app.activitythread.access$600(activitythread.java:156) e/windowmanager(18015): @ android.app.activitythread$h.handlemessage(activitythread.java:1340) e/windowmanager(18015): @ android.os.handler.dispatchmessage(handler.java:99) e/windowmanager(18015): @ android.os.looper.loop(looper.java:153) e/windowmanager(18015): @ android.app.activitythread.main(activitythread.java:5297) e/windowmanager(18015): @ java.lang.reflect.method.invokenative(native method) e/windowmanager(18015): @ java.lang.reflect.method.invoke(method.java:511) e/windowmanager(18015): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) e/windowmanager(18015): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) e/windowmanager(18015): @ dalvik.system.nativestart.main(native method)

amazon-web-services amazon-s3 android-asynctask

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -