First of all, Thank you for reply...the scenario is:
after struggling with download attachment endpoit, i got it work. :))), now i am working on upload attachment endpoint.
what i have done is:
1. i generate a web request object for this url: http://mail.yahooapis.com/ya/upload?uploadfile=" + file.FileName + "&output=json; with authorization header, same as download attachment web request.
2. i convert the file content to array of bytes, and i save the file in my project local path.
3. set the method to POST.
4. and set the Content-Type in the header to : multipart/form-data.
5. convert to the array of bytes to base64.
6. write the content to a request stream
..and the error is FileUploadSizeError.
i dont know why...
i have tried many senarios,
--sending full path of file in the questy string fileupload
--sending with request stream and without writing into a stream.
please help.
this is my code:
/***Upload Attachment**/
string dt = DateTime.Now.ToString("ddMMyyyyHHmmss");
file.SaveAs(Server.MapPath("/Uploaded/yahoo/"+dt+"-"+file.FileName));
MemoryStream ms = new MemoryStream();
file.InputStream.CopyTo(ms);
byte[] datacontent = ms.ToArray();
ms.Dispose();
string base64filecontent = Convert.ToBase64String(datacontent);
HttpWebResponse response;
Stream stream;
Uri uri = new Uri("http://mail.yahooapis.com/ya/upload?uploadfile=" + file.FileName + "&output=json");
string oauth_token = yhModel.OAuth_AccessToken;
string oauth_secret = yhModel.OAuth_TokenSecret;
HttpWebRequest webrequest = yhModel.GetWebRequest(oauth_token, oauth_secret, uri, "POST");
webrequest.Method = "POST";
webrequest.ContentType = "multipart/form-data";
StringBuilder content = new System.Text.StringBuilder();
content.AppendLine(base64filecontent);
byte[] postdata = System.Text.Encoding.UTF8.GetBytes(content.ToString());
webrequest.ContentLength = postdata.Length;
Stream s = webrequest.GetRequestStream();
s.Write(postdata, 0, postdata.Length);
s.Flush();
s.Close();
HttpWebResponse res = (HttpWebResponse)webrequest.GetResponse();
/**BuildWebRequest****/
DataTable dtResult = MyIBoxModel.GetAPP_AccountCredentials(3);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
oAuthBase oauth = new oAuthBase();
string nonce = oauth.GenerateNonce();
string timestamp = oauth.GenerateTimeStamp();
string consumerKey = dtResult.Rows[0]["APP_KEY"].ToString();
string consumerSecret = dtResult.Rows[0]["APP_SECRET"].ToString();
string p = "", h = "";
string signature = oauth.GenerateSignature(uri, consumerKey, consumerSecret, oauth_token, oauth_secret, strMethod, timestamp, nonce,out p,out h);
webRequest.Headers.Add("Authorization", "OAuth oauth_nonce=\"" + nonce + "\"" +
", oauth_timestamp=\""+timestamp+"\""+
", oauth_version=\"1.0"+"\""+
", oauth_signature_method=\"HMAC-SHA1"+"\""+
", oauth_consumer_key=\""+consumerKey+"\""+
", oauth_token=\""+oauth_token+"\""+
", oauth_signature=\""+signature+"\"");
return webRequest;..
...
can you write pseudo code for upload attachment...
url, query strings, headers, authorization, should i send a request stream of file content....
please....:(
Thanx alot
QUOTE
(ram @ 4 Sep 2012 3:43 PM)Can you please explain the problem you are facing?