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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:49:40+00:00 2026-05-23T16:49:40+00:00

I m trying to upload a new photo to picasa using the API. code

  • 0

I m trying to upload a new photo to picasa using the API.
code not working
I am getting the following error:

Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.

My Code:

string imgPath = "C:\foo.png"; 
StreamReader reader = new StreamReader(imgPath); 
string imgBin = reader.ReadToEnd(); 
reader.Close();
string id=""//picasa ID
string album = "";//album name
string url = String.Format("http://www.picasaweb.google.com/data/feed/api/user/{0}/album/{1}",id, album);
string auth = "";

        Byte[] send = Encoding.UTF8.GetBytes(imgBin); 
        int length = send.Length;
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
        req.Method = "POST";
        req.ContentType = "image/png";
        req.ContentLength = length;
        req.Headers.Add("Authorization", "GoogleLogin auth=" + auth);
        req.Headers.Add("Slug", "test");
        Stream stream = req.GetRequestStream();
        stream.Write(send, 0, length);
        stream.Close();
        WebResponse response = req.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string res = reader.ReadToEnd();
        reader.Close();

Thanks

  • 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-23T16:49:41+00:00Added an answer on May 23, 2026 at 4:49 pm

    The problem is most likely with how you are reading the image. Instead of reading it as a string, try writing it directly into the request stream, similar to the following:

    using (Stream fileStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read))
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "image/png";
        request.ContentLength = fileStream.Length;
        request.Headers.Add(HttpRequestHeader.Authorization, "GoogleLogin auth=" + auth);
        request.Headers.Add("Slug", "test");
    
        using (Stream requestStream = request.GetRequestStream())
        {
            byte[] buffer = new byte[4096];
            int bytesRead = 0;
            while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
            {
                requestStream.Write(buffer, 0, bytesRead);
            }
    
            fileStream.Close();
            requestStream.Close();
        }
    
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader responseReader = new StreamReader(response.GetResponseStream());
    
        string responseStr = responseReader.ReadToEnd();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to upload a photo to facebook using graph api and keep
I'm getting an an error when trying to upload a new version of my
js.I am trying to create a file upload using node.js and mongodb.I am getting
I am trying to upload a file with ASP.NET MVC. The following code work
I am trying to upload images to ImageShack using the API. I think they
I'm trying to upload documents to SharePoint using web services attaching custom metadata to
I am trying to upload file using php. I am using the function move_uploaded_file.
I'm trying to upload a file using Watin and C#. Under Windows XP, Watin
i am trying to upload an image from a jsp page using servlet. but
I'm trying to familiarize myself with Facebook's new Graph API and so far I

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.