private string UploadData(Stream imageStream, string fileName, Uri uploadUri, Dictionary <string, string> parameters)
{
string boundary = "FLICKR_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo);
string authHeader = FlickrResponder.OAuthCalculateAuthHeader(parameters);
byte[] dataBuffer = CreateUploadData(imageStream, fileName, parameters, boundary);
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uploadUri);
//req.UserAgent = "Mozilla/4.0 FlickrNet API (compatible; MSIE 6.0; Windows NT 5.1)";
req.Method = "POST";
if (Proxy != null)
{
req.Proxy = Proxy;
}
req.Timeout = HttpTimeout;
req.ContentType = "multipart/form-data; boundary=" + boundary;
//req.Expect = String.Empty;
if (!String.IsNullOrEmpty(authHeader))
{
req.Headers["Authorization"] = authHeader;
}
req.ContentLength = dataBuffer.Length;
using (Stream reqStream = req.GetRequestStream())
{
int bufferSize = 32 * 1024;
if (dataBuffer.Length / 100 > bufferSize)
{
bufferSize = bufferSize * 2;
}
int uploadedSoFar = 0;
while (uploadedSoFar < dataBuffer.Length)
{
reqStream.Write(dataBuffer, uploadedSoFar, Math.Min(bufferSize, dataBuffer.Length - uploadedSoFar));
uploadedSoFar += bufferSize;
if (OnUploadProgress != null)
{
UploadProgressEventArgs args = new UploadProgressEventArgs(uploadedSoFar, dataBuffer.Length);
OnUploadProgress(this, args);
}
}
reqStream.Close();
}
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string s = sr.ReadToEnd();
sr.Close();
return(s);
}