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 3607472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:22:48+00:00 2026-05-18T21:22:48+00:00

Looking for some code to upload a photo to facebook using the Graph API

  • 0

Looking for some code to upload a photo to facebook using the Graph API in VB.NET. I have the Facebook C# SDK, but it doesn’t support uploading photos as far as I can tell.

Accessing the photos works fine and I can send other content to Facebook fine as well. Just not photos.

The facebook documentation talks about attaching the file as a form-multipart request, but I have no idea how to do that. To say that its not very well documented is to put it lightly. Even the guys I hire to do this kind of thing couldn’t get it to work.

I’ve found this: Upload Photo To Album with Facebook's Graph API, but it only describes how to do it in PHP.

I’ve also seen varying method from different sites about passing the URL of the photo as a part of the HTTP request, but after trying local or remote URLs several times I kept getting a bad url error or something like that.

Any thoughts?

  • 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-18T21:22:48+00:00Added an answer on May 18, 2026 at 9:22 pm

    You need to pass the Image in a POST request to the Graph API (Need publish_stream permission). What is mentioned in Facebook Documentation is correct. Following is the example code that may do the work. use it inside a method. (Code is in C#)

    Legend
    <content> : you need to provide the info.

    Update
    Please post comments to improve the code.

    string ImageData;
    string queryString = string.Concat("access_token=", /*<Place your access token here>*/);
    string boundary = DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture);
    
    StringBuilder sb = String.Empty;
    sb.Append("----------").Append(boundary).Append("\r\n");
    sb.Append("Content-Disposition: form-data; filename=\"").Append(/*<Enter you image's flename>*/).Append("\"").Append("\r\n");
    sb.Append("Content-Type: ").Append(String.Format("Image/{0}"/*<Enter your file type like jpg, bmp, gif, etc>*/)).Append("\r\n").Append("\r\n");
    
    using (FileInfo file = new FileInfo("/*<Enter the full physical path of the Image file>*/"))
    {
        ImageData = file.OpenText().ReadToEnd();
    }
    byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sb.ToString());
    byte[] fileData = Encoding.UTF8.GetBytes(ImageData);
    byte[] boundaryBytes = Encoding.UTF8.GetBytes(String.Concat("\r\n", "----------", boundary, "----------", "\r\n"));
    var postdata = new byte[postHeaderBytes.Length + fileData.Length + boundaryBytes.Length];
    Buffer.BlockCopy(postHeaderBytes, 0, postData, 0, postHeaderBytes.Length);
    Buffer.BlockCopy(fileData, 0, postData, postHeaderBytes.Length, fileData.Length);
    Buffer.BlockCopy(boundaryBytes, 0, postData, postHeaderBytes.Length + fileData.Length, boundaryBytes.Length);
    
    var requestUri = new UriBuilder("https://graph.facebook.com/me/photos");
    requestUri.Query = queryString;
    var request = (HttpWebRequest)HttpWebRequest.Create(requestUri.Uri);
    request.Method = "POST";
    request.ContentType = String.Concat("multipart/form-data; boundary=", boundary);
    request.ContentLength = postData.Length;
    
    using (var dataStream = request.GetRequestStream())
    {
          dataStream.Write(postData, 0, postData.Length);
    }
    
    request.GetResponse();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I was looking at some code atually from Nikhil Kothari's Facebook.NET API. I
I have some C# code that will upload images and files into a db.
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
Looking at some code I'm maintaining in System Verilog I see some signals that
I am looking at some code and it has this statement: ~ConnectionManager() { Dispose(false);
OK so I'm looking a some code which looks roughly like this: void DoSomething(object
Looking for some sample code (C#) for a simple thread pool implementation. I found
I'm looking for some sample code that will sort the list items in an
I'm looking at some GXT code for GWT and I ran across this use
I am looking at some javascript code and it has this in a function:

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.