Have you looked at the inner exception? It’s possible that the message/details 
in there will tell you what you’re missing.

Also, it looks kindof complicated/hairy to be putting together the web request 
yourself - so many things to get wrong. Is there not a C# client library (like 
there is in Java) to take away some of this complexity and potentially give you 
better error messages? If not, you could try using IKVM to cross-compile the 
java client library Jars into .Net - I’ve had success in doing that in the 
past. 

On 20 May 2015, at 11:32, Prerana Polekar <[email protected]> wrote:

Hello All,
I am trying to upload a image with metadata using Picasa Web Album Data API 
version 2.0 in C#. Its throwing 'Bad Request' error. The error does not 
indicate which part in request is missing or where I am going wrong. The image 
upload without metadata works perfectly. Following is the code :


    byte[] image = System.IO.File.ReadAllBytes(fullimagepath);
                int imglenth= image.Length;
               string rawImgXml="<entry 
xmlns=\'http://www.w3.org/2005/Atom\'>"+"\n"+
                    "<title>plz-to-love-realcat.jpg</title>"+"\n"+
                    "<summary>Real cat wants attention too</summary>"+"\n"+
                    "<category 
scheme=\"http://schemas.google.com/g/2005#kind\""+
                    
"term=\"http://schemas.google.com/photos/2007#photo\"/>"+"\n"+
                    "</entry>";

                string data = "";
                 data ="\nMedia multipart posting\n"+
                          "--P4CpLdIHZpYqNn7\n"+
                          "Content-Type: application/atom+xml\n\n"+
                            rawImgXml + "\n"
                           +"--P4CpLdIHZpYqNn7\n"
                           +"Content-Type: image/jpeg\n\n"+
                            "--P4CpLdIHZpYqNn7--";
                int length=data.Length+imglenth;

                HttpWebRequest request = 
(HttpWebRequest)WebRequest.Create("https://picasaweb.google.com/data/feed/api/user/"+tc.userId+"/albumid/"+"6150508893827643953"+"?access_token="+tc.auth_Token);
                byte[] bytes;
                bytes = System.Text.Encoding.ASCII.GetBytes(data);
                request.ContentType = "multipart/related; 
boundary=P4CpLdIHZpYqNn7";
                request.ContentLength = length;
                request.Headers.Add("GData-Version","2");
                request.Headers.Add("MIME-Version","1.0");
                request.Method = "POST";
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(image, 0, image.Length);
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();
                HttpWebResponse response;
                response = (HttpWebResponse)request.GetResponse();

                Stream responseStream = response.GetResponseStream();
                string responseStr = new 
StreamReader(responseStream).ReadToEnd();

Where am I going wrong? Instead of attaching the image binary data in the 
string named 'data' I am writing it to the stream, is that the culprit? Any 
suggestions or directions will be of great help. Thanks a ton in advance!

-Prerana  

                  

-- 
You received this message because you are subscribed to the Google Groups 
"Google Picasa Web Albums API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected] 
<mailto:[email protected]>.
To post to this group, send email to [email protected] 
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/google-picasa-data-api 
<http://groups.google.com/group/google-picasa-data-api>.
For more options, visit https://groups.google.com/d/optout 
<https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Picasa Web Albums API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-picasa-data-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to