|
|
Thread Tools | Display Modes |
|
#1
|
|
|
Big grins
|
"underlying connection was closed: The connection was closed unexpectedly" big file
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. |
|
|
|
|
#2
|
|
|
panasonikon
|
Hi, what uploader are you using?
|
|
|
|
|
#3
|
|
|
Big grins
|
|
|
|
|
|
#4
|
|
|
Big grins
|
underlying Connection Was Closed: The Connection Was Closed Unexpectedly
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. |
|
|
|
|
#5
|
|
|
technicolored
|
Hi,
What's your SmugMug nickname so that I can do some digging ? Thanks, David |
|
|
|
|
#6
|
|
|
Big grins
|
|
|
|
|
|
#7
|
||
|
with a Heroes touch
|
Quote:
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.
__________________
Sebastian SmugMug Support Hero look on the bright side http://www.SebastianHosche.com |
|
|
|
||
| Tell The World! | |
| Similar Threads | Thread Starter | Forum | Replies | Last Post | ![]() |
| Un-official Unsolicited Vista and Windows 7 Advice Thread | Pupator | Digital Darkroom | 365 | May-15-2012 12:04 PM | |
| smugDAV - let's get this show on the road | rteng | SmugMug APIs, Hacks & Tricks | 20 | Feb-04-2008 03:11 PM | |
| File Upload - Original File MD5Sum Changes | mjohnsonperl | SmugMug APIs, Hacks & Tricks | 9 | Oct-24-2007 01:38 PM | |
| Thread Tools | |
| Display Modes | |
|
|