0

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());
        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?

2 Answers 2

2

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));
Sign up to request clarification or add additional context in comments.

1 Comment

Uri constructor does not exist. anyways thanks yes i got the answer InputStream fis = this.getContentResolver().openInputStream(Uri.parse(uriString));
0

Did you add:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

to your AndroidManifest?

1 Comment

no i did not :( and second thing i just want to read image and upload so i might need reading permission Right? and thanks for reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.