Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8901529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:22:43+00:00 2026-06-15T01:22:43+00:00

I saved the Uri String of an image to SQLite as string. I can

  • 0

I saved the Uri String of an image to SQLite as string. I can view the image by creating a view intent for it.

but when I upload the image to the web server using FileBody(new File(theUriFromTheDatabase)) it always saying “open failed: ENOENT (No such file or directory)”

The file’s uri is: “/content:/media/external/images/media/667”

Facts:

  1. I’m sure the file is there because I can view it
  2. I enabled internal storage read/write, external storage read/write permissions
  3. Using a Galaxy Tab 2 10.1
  4. It doesn’t have an SD card
  5. Same code works on my Experia Neo V with SD card (is it because it has no SD card?)
  6. Tried removing the wire before starting the app
  7. Tethered USB is off

Here is the code:

    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub

        InspectionsDbController db = new InspectionsDbController(getActivity());

        InspectionItemStruct[] ins = db.getInspectionList(((MyApplication)((Activity) mContext).getApplication()).getCurrentInspectionId());

        SharedPreferences settings = mContext.getSharedPreferences(MainActivity.PREFS_NAME, 0);
        long userId = settings.getLong("userId", 0);
        String token = settings.getString("token", "");

        for (int i = 0; i < ins.length; i++) {


            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost("http://webprojectupdates.com/mmp/api/mobile/upload_inspection");


                MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

                // add userId
                try {  
                    entity.addPart("userId", new StringBody(String.valueOf(userId)));
                    entity.addPart("token", new StringBody(String.valueOf(token)));

                } catch (IOException e) {
                    Log.e("MMP","Error in adding token: "+e.getMessage());
                }




                // add media attachments
                if(ins[i].image!=null){


                    //Bitmap image = BitmapFactory.decodeFile(ins[i].image);

                    //ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    //image.compress(CompressFormat.JPEG, 75, bos);
                    //byte[] imageData = bos.toByteArray();
                    //ByteArrayBody bab = new ByteArrayBody(imageData,"image/jpg", ins[i].itemId+".jpg");

                    //entity.addPart("image", bab);
                    entity.addPart("image", new FileBody(new File (ins[i].image)));
                }
                if(ins[i].video!=null){
                    entity.addPart("video", new FileBody(new File (ins[i].video)));
                }

                // Normal string data
                try {  
                    entity.addPart("itemId", new StringBody(String.valueOf(ins[i].itemId)));
                    entity.addPart("isExist", new StringBody(String.valueOf(ins[i].itemExists)));
                    if(ins[i].comments!=null)  entity.addPart("comment", new StringBody(String.valueOf(ins[i].comments)));
                    entity.addPart("condition", new StringBody(String.valueOf(ins[i].condition)));
                } catch (IOException e) {
                    Log.e("MMP","Error in adding inspection data: "+e.getMessage());
                }

                try { 
                    httpPost.setEntity(entity);
                    HttpResponse response = httpClient.execute(httpPost, localContext);
                    String result = EntityUtils.toString(response.getEntity());
                } catch (IOException e) {
                    Log.e("MMP","Error in handling result: "+e.getMessage());
                }



            publishProgress(i+1,ins.length);
        }
        return null;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:22:45+00:00Added an answer on June 15, 2026 at 1:22 am

    It needed the filename instead if the uri string. thanks @mh

    ContentResolver cr = mContext.getContentResolver();
    String[] projection = {MediaStore.MediaColumns.DATA};
    Cursor cur = cr.query(Uri.parse(ins[i].image), projection, null, null, null);
    if(cur != null) {
        cur.moveToFirst();
        String filePath = cur.getString(0);
        File imageFile = new File(filePath);
        if(imageFile.exists()) {
            // do something if it exists
            entity.addPart("image", new FileBody(imageFile));
        }
        else {
            // File was not found
            Log.e("MMP","Image not Found");
        }
    } 
    else {
        // content Uri was invalid or some other error occurred
        Log.e("MMP","Invalid content or some error occured");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the below code for saving an image to SD Card. But
I saved a path of an image taken by the camera into sqlite DB
i am using following code for capturing the image in Android: String fileName =
I saved some data in the database using mysql_real_escape_string() so the single quotes are
I have never saved and retrieved an image to and from the database before.
I have saved an html page using the following line of code : NSURL
I have saved an image path in database like so: C:\Users\3embed\Documents\Visual Studio 2010\Projects\HeritageWeb\HeritageWeb\Images\startbutton.png I
I'm trying to build an OCR application on Android using Tesseract, but when I
Hey trying to read stream into image control can any one help also I
how can I save a Bitmap Image to the sdcard with loosing it's original

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.