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

  • SEARCH
  • Home
  • 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 6060075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:47:02+00:00 2026-05-23T08:47:02+00:00

I am trying to upload a photo to facebook using graph api and keep

  • 0

I am trying to upload a photo to facebook using graph api and keep getting OutOfMemory exception.
The code for the upload is this:

private void PostPhoto(SessionHandler facebook, Uri photoUri)
{
    Bundle params = new Bundle();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    String realPath = getRealPathFromURI(photoUri); 
    Bitmap bitmap = BitmapFactory.decodeFile(realPath);

    bitmap.compress(CompressFormat.JPEG, 100, bos);

    params.putByteArray("picture", bos.toByteArray());


    try
    {
        facebook.mFacebook.request("me/photos", params, "POST");            

    } catch (FileNotFoundException fileNotFoundException)
    {

    } catch (MalformedURLException malformedURLException)
    {

    } catch (IOException ioException)
    {

    }

}

The exception raises on the decodeFile function and sometimes in the facebook SDK itself when it calls this line:

return Util.openUrl(url, httpMethod, parameters);

inside the request function.

The app is getting the picture content:// Uri by the ACTION_SEND intent.
getRealPathFromURI() is used to translate the content:// uri to a real sdcard path.

Any ideas?

  • 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-05-23T08:47:03+00:00Added an answer on May 23, 2026 at 8:47 am

    Try this, it works for me:

    byte[] data = null;
    try {
        ContentResolver cr = mainActivity.getContentResolver();
        InputStream fis = cr.openInputStream(photoUri);
        Bitmap bi = BitmapFactory.decodeStream(fis);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        data = baos.toByteArray();              
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }     
    Bundle params = new Bundle(); 
    params.putString("method", "photos.upload");          
    params.putByteArray("picture", data);
    

    This is using the Rest API, the facebook sdk has the method for calling it so just change your request line from:

    facebook.mFacebook.request("me/photos", params, "POST");   
    

    to:

    facebook.mFacebook.request(params);   
    

    and hopefully that will solve the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for some code to upload a photo to facebook using the Graph API
i am trying to upload photo to facebook using fiddler In the request builder
I was trying to upload a photo on facebook using a browser with no
I am trying to upload a photo using the API and am having an
I'm trying to upload images using Graph API Batch Request, but i'm unable to
In my iPhone app, I am trying to upload photo on facebook wall using
I am trying to upload an image through my application with Facebook Graph API
I'm trying to familiarize myself with Facebook's new Graph API and so far I
Im trying to do a simple script with this: How-To: Use the Graph API
im trying to make facebook upload photo with random tag friend. the program was

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.