file not found exception while uploading file to web server?
I am using following tutorial to upload image file to webserver.
and getting file not found exception here.
try {
File uploadFile = new File(uriString);
// file path i receive **content:/media/external/images/media/2**
FileInputStream fis = this.openFileInput(uploadFile.getName()); // **ERRoR HERE**
HttpFileUploader htfu = new HttpFileUploader("http://finditnear.sigmatec.com.pk/inbox/send_remote_reply","noparamshere", uploadFile.getName());
开发者_如何学Go htfu.doStart(fis);
}
catch (FileNotFoundException e) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
return;
}
image file exists there but still it giving me error.
Can any one guide me what is the solution?
content:/media/external/images/media/2 is incorrect file name, it's a Uri.
So this line
FileInputStream fis = this.openFileInput(uploadFile.getName());
Should be replaced with
InputStream fis=this.getContentResolver().openInputStream(new Uri(uriString));
Did you add:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to your AndroidManifest
?
精彩评论