Picasa Web Album Data API v2:(400)错误请求'上传带有元数据的照片时抛出错误
本文关键字:错误 元数据 出错 照片 API Data Album Web v2 请求 Picasa | 更新日期: 2023-09-27 17:50:32
我正在尝试使用Picasa Web Album Data API v2在c#中上传带有元数据的图像,正如这里的文档中提到的。
http post请求失败,400错误请求错误,没有详细说明我的请求缺失或哪里是畸形的
下面是我的代码: byte[] image = System.IO.File.ReadAllBytes("fullimagepath");
int imglenth= image.Length;
string text = Encoding.ASCII.GetString(image);
string rawImgXml="<entry xmlns=''http://www.w3.org/2005/Atom''>"+"'n"+
"<title>plz-to-love-realcat.png</title>"+"'n"+
"<summary>Real cat wants attention too</summary>"+"'n"+
"<category scheme='"http://schemas.google.com/g/2005#kind'"'n"+
"term='"http://schemas.google.com/photos/2007#photo'"/>"+"'n"+
"</entry>";
string data = "";
data ="'nMedia multipart posting'n"+
"--END_OF_PART'n"+
"Content-Type: application/atom+xml'n'n"+
rawImgXml + "'n"
+"--END_OF_PART'n"
+"Content-Type: image/png'n"+
text+"'n"+
"--END_OF_PART--";
int length=data.Length;
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=END_OF_PART";
request.ContentLength = length;
request.Headers.Add("GData-Version","2");
request.Headers.Add("MIME-Version","1.0");
request.Method = "POST";
Stream requestStream = request.GetRequestStream();
int start = 0;
int chunkSize = 1024 * 4; // changed form 100 to 4
double percentage = 0;
while (start <= bytes.Length)
{
if (start + chunkSize > bytes.Length)
requestStream.Write(bytes, start, bytes.Length - start);
else
requestStream.Write(bytes, start, chunkSize);
start += chunkSize;
}
HttpWebResponse response;
response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
string responseStr = new StreamReader(responseStream).ReadToEnd();
图像数据正在被转换为ASCII,然后附加到数据字符串。在尝试了过去3天的许多排列和组合后,它失败了,同样的错误。完全不知道请求哪里出了问题?
上传没有元数据的图像工作完美,但我想在我的应用程序中也上传视频,这不能没有元数据。
任何指示或指针将大有帮助!提前非常感谢!
当我尝试上传带有元数据的照片时,同样的问题在这里,但是没有元数据它工作得很好。
你可以试试这个请求:https://developers.google.com/picasa-web/docs/2.0/developers_guide_protocol#PostPhotos并让我们知道它的效果如何吗?