"underlying connection was closed: The connection was closed unexpectedly" big file
sujit1779
Registered Users Posts: 46 Big grins
Hi,
When I try to upload image file around 10 MB, I get this error
"underlying connection was closed: The connection was closed unexpectedly"
Below is my code, can anyone help me out?
=================================
HttpWebResponse response = null;
HttpWebRequest request = null;
Stream str = null;
bool error = false;
StreamReader sr = null;
OAuth.OAuthBase myOAuth = new OAuth.OAuthBase();
string normalizedUrl;
string normalizedRequestParameters;
Uri uri = new Uri("http://upload.smugmug.com/" + Path.GetFileName(path));
string timeStamp = myOAuth.GenerateTimeStamp();
string nonce = myOAuth.GenerateNonce();
myOAuth.includeVersion = true;
string signature = myOAuth.GenerateSignature(uri, Smugmug_CONSUMER_KEY, Smugmug_CONSUMER_SECRET, SmugmugAuthToken
, SmugmugAuthSecret, "PUT", timeStamp, nonce, OAuth.OAuthBase.SignatureTypes.HMACSHA1,
out normalizedUrl, out normalizedRequestParameters);
// string path = @K:\pics and video\New folder\DSC02235.JPG;
byte[] image = System.IO.File.ReadAllBytes(path);
string hash = calculateMD5Hash(image);
int size = image.Length;
request = (HttpWebRequest)WebRequest.Create("http://upload.smugmug.com/" + Path.GetFileName(path));
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
request.Method = "PUT";
request.ContentLength = size;
request.Timeout = 2147483647;
request.ReadWriteTimeout = 2147483647;
request.ContentType = ContentType(Path.GetExtension(path));
request.Headers["Content-MD5"] = hash;
request.Headers.Add("Authorization", "OAuth oauth_consumer_key=\"" + Smugmug_CONSUMER_KEY + "\",oauth_token=\"" + SmugmugAuthToken
+ "\",oauth_signature_method=\"HMAC-SHA1\",oauth_signature=\"" + HttpUtility.UrlEncode(signature) + "\",oauth_timestamp=\"" + timeStamp + "\",oauth_nonce=\"" + nonce + "\", oauth_version=\"1.0\"");
request.Headers.Add("X-Smug-Version", "1.2.0");
request.Headers.Add("X-Smug-ResponseType", "JSON");
request.Headers.Add("X-Smug-AlbumID", albumId);
request.Headers.Add("X-Smug-FileName", Path.GetFileName(path));
request.Headers.Add("Content-Length", size.ToString());
str = request.GetRequestStream();
str.Write(image, 0, size);
str.Flush();
str.Close();
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
}
=================================
Thanks.
When I try to upload image file around 10 MB, I get this error
"underlying connection was closed: The connection was closed unexpectedly"
Below is my code, can anyone help me out?
=================================
HttpWebResponse response = null;
HttpWebRequest request = null;
Stream str = null;
bool error = false;
StreamReader sr = null;
OAuth.OAuthBase myOAuth = new OAuth.OAuthBase();
string normalizedUrl;
string normalizedRequestParameters;
Uri uri = new Uri("http://upload.smugmug.com/" + Path.GetFileName(path));
string timeStamp = myOAuth.GenerateTimeStamp();
string nonce = myOAuth.GenerateNonce();
myOAuth.includeVersion = true;
string signature = myOAuth.GenerateSignature(uri, Smugmug_CONSUMER_KEY, Smugmug_CONSUMER_SECRET, SmugmugAuthToken
, SmugmugAuthSecret, "PUT", timeStamp, nonce, OAuth.OAuthBase.SignatureTypes.HMACSHA1,
out normalizedUrl, out normalizedRequestParameters);
// string path = @K:\pics and video\New folder\DSC02235.JPG;
byte[] image = System.IO.File.ReadAllBytes(path);
string hash = calculateMD5Hash(image);
int size = image.Length;
request = (HttpWebRequest)WebRequest.Create("http://upload.smugmug.com/" + Path.GetFileName(path));
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
request.Method = "PUT";
request.ContentLength = size;
request.Timeout = 2147483647;
request.ReadWriteTimeout = 2147483647;
request.ContentType = ContentType(Path.GetExtension(path));
request.Headers["Content-MD5"] = hash;
request.Headers.Add("Authorization", "OAuth oauth_consumer_key=\"" + Smugmug_CONSUMER_KEY + "\",oauth_token=\"" + SmugmugAuthToken
+ "\",oauth_signature_method=\"HMAC-SHA1\",oauth_signature=\"" + HttpUtility.UrlEncode(signature) + "\",oauth_timestamp=\"" + timeStamp + "\",oauth_nonce=\"" + nonce + "\", oauth_version=\"1.0\"");
request.Headers.Add("X-Smug-Version", "1.2.0");
request.Headers.Add("X-Smug-ResponseType", "JSON");
request.Headers.Add("X-Smug-AlbumID", albumId);
request.Headers.Add("X-Smug-FileName", Path.GetFileName(path));
request.Headers.Add("Content-Length", size.ToString());
str = request.GetRequestStream();
str.Write(image, 0, size);
str.Flush();
str.Close();
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
}
=================================
Thanks.
0
Comments
Portfolio • Workshops • Facebook • Twitter
Hi , I am not using any uploader. I am using REST
Is there any image size limitation for API upload (free or Pro users).
Thanks.
Hi,
When I try to upload a big image using C# and API, I get this error
underlying Connection Was Closed: The Connection Was Closed Unexpectedly
My code works perfectly if small size image is uploaded. Can someone point me what to do?
below is my code
==============
Below is my code, can anyone help me out?
=================================
HttpWebResponse response = null;
HttpWebRequest request = null;
Stream str = null;
bool error = false;
StreamReader sr = null;
OAuth.OAuthBase myOAuth = new OAuth.OAuthBase();
string normalizedUrl;
string normalizedRequestParameters;
Uri uri = new Uri("http://upload.smugmug.com/" + Path.GetFileName(path));
string timeStamp = myOAuth.GenerateTimeStamp();
string nonce = myOAuth.GenerateNonce();
myOAuth.includeVersion = true;
string signature = myOAuth.GenerateSignature(uri, Smugmug_CONSUMER_KEY, Smugmug_CONSUMER_SECRET, SmugmugAuthToken
, SmugmugAuthSecret, "PUT", timeStamp, nonce, OAuth.OAuthBase.SignatureTypes.HMACSHA1,
out normalizedUrl, out normalizedRequestParameters);
// string path = @K:\pics and video\New folder\DSC02235.JPG;
byte[] image = System.IO.File.ReadAllBytes(path);
string hash = calculateMD5Hash(image);
int size = image.Length;
request = (HttpWebRequest)WebRequest.Create("http://upload.smugmug.com/" + Path.GetFileName(path));
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
request.Method = "PUT";
request.ContentLength = size;
request.Timeout = 2147483647;
request.ReadWriteTimeout = 2147483647;
request.ContentType = ContentType(Path.GetExtension(path));
request.Headers["Content-MD5"] = hash;
request.Headers.Add("Authorization", "OAuth oauth_consumer_key=\"" + Smugmug_CONSUMER_KEY + "\",oauth_token=\"" + SmugmugAuthToken
+ "\",oauth_signature_method=\"HMAC-SHA1\",oauth_signature=\"" + HttpUtility.UrlEncode(signature) + "\",oauth_timestamp=\"" + timeStamp + "\",oauth_nonce=\"" + nonce + "\", oauth_version=\"1.0\"");
request.Headers.Add("X-Smug-Version", "1.2.0");
request.Headers.Add("X-Smug-ResponseType", "JSON");
request.Headers.Add("X-Smug-AlbumID", albumId);
request.Headers.Add("X-Smug-FileName", Path.GetFileName(path));
request.Headers.Add("Content-Length", size.ToString());
str = request.GetRequestStream();
str.Write(image, 0, size);
str.Flush();
str.Close();
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
}
=================================
Can someone help me out, I am in urgent need of solution.
Thanks.
What's your SmugMug nickname so that I can do some digging ?
Thanks,
David
SmugMug API Developer
My Photos
I am uploading using id "picbackman1995@gmail.com", can you tell me why isn't it getting uploaded.
Thanks
The "incomplete file" error tells you that the file in question wasn't received completely. During the upload, the connection was likely somehow interrupted. If you're on wireless, try a hard-wired cable connection to your router instead.
It could also be your antivirus, firewall or internet security software interfering.
As for the "invalid file type" errors, that tells you that we didn't recognize the file. The photos might be in a color space that we don't support or perhaps they contain some metadata that we don't support or are corrupted in some way. You can try resaving such photos (using sRGB color profile) in a photo editing program which usually helps. If not, email the HelpDesk with a sample file gets rejected with the "invalid file type" error for us to look at.
SmugMug Support Hero