"underlying connection was closed: The connection was closed unexpectedly" big file

sujit1779sujit1779 Big grinsPosts: 46Registered Users 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.

Comments

  • AndyAndy Bicameral New YorkPosts: 60,808Registered Users Major grins
    edited April 26, 2012
    Hi, what uploader are you using?
  • sujit1779sujit1779 Big grins Posts: 46Registered Users Big grins
    edited April 28, 2012
    Andy wrote: »
    Hi, what uploader are you using?

    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.
  • sujit1779sujit1779 Big grins Posts: 46Registered Users Big grins
    edited April 30, 2012
    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.
  • devbobodevbobo LR whisperer Posts: 4,335Administrators moderator
    edited April 30, 2012
    Hi,

    What's your SmugMug nickname so that I can do some digging ?

    Thanks,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • sujit1779sujit1779 Big grins Posts: 46Registered Users Big grins
    edited October 12, 2012
    devbobo wrote: »
    Hi,

    What's your SmugMug nickname so that I can do some digging ?

    Thanks,

    David

    I am uploading using id "picbackman1995@gmail.com", can you tell me why isn't it getting uploaded.

    Thanks
  • rainforest1155rainforest1155 SmugMug Support Hero Posts: 4,422Registered Users Major grins
    edited October 14, 2012
    sujit1779 wrote: »
    I am uploading using id "picbackman1995@gmail.com", can you tell me why isn't it getting uploaded.

    Thanks
    Did you take a look at your upload log (account settings > stats > uploads > details)? There select "month" and you'll see a number of different errors.

    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
Sign In or Register to comment.