Options

"Expired timestamp" response I receive when I upload a big video file using API

sujit1779sujit1779 Registered Users Posts: 46 Big grins
Hi,

I was uploading a big video file, 25 MB using API and I received this response (error)

{
"STAT": "FAIL",
"METHOD": "SMUGMUG.IMAGES.UPLOAD",
"CODE": 30,
"MESSAGE": "EXPIRED TIMESTAMP"
}

upload took almost 30 mins and thats why I think timestamp might expire.

What should I do in cases where upload takes a long time, how can I get rid of this error.

Thanks.

Comments

  • Options
    devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited October 16, 2012
    G'day,

    For uploads, we validate against the time the connection was opened rather than the time that the upload finished for this very reason.

    I can verify that we have lots of long video uploads with our LR plugin that would have expired if we used the time the upload finished.

    Please double check that your date/time is correct. For the LR plugin, we use the 'Date' response header to compare against the sent oauth_timestamp to automatically adjust the future oauth_timestamps. It's a method that works well to prevent those sort of errors, you might find it useful as well.

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • Options
    sujit1779sujit1779 Registered Users Posts: 46 Big grins
    edited October 18, 2012
    devbobo wrote: »
    G'day,

    For uploads, we validate against the time the connection was opened rather than the time that the upload finished for this very reason.

    I can verify that we have lots of long video uploads with our LR plugin that would have expired if we used the time the upload finished.

    Please double check that your date/time is correct. For the LR plugin, we use the 'Date' response header to compare against the sent oauth_timestamp to automatically adjust the future oauth_timestamps. It's a method that works well to prevent those sort of errors, you might find it useful as well.

    Cheers,

    David

    Thanks David for the reply. What I am doing in my code is that I am writing in parts (i.e chunks), so is it possible that when the last part gets written timestamp gets expired? Below is my code for your reference

    Uri url = new Uri("http://upload.smugmug.com/");
    string timeStamp = base2.GenerateTimeStamp();
    string nonce = base2.GenerateNonce();
    base2.includeVersion = true;
    string str5 = base2.GenerateSignature(url, this.Smugmug_CONSUMER_KEY, this.Smugmug_CONSUMER_SECRET, this.SmugmugAuthToken, this.SmugmugAuthSecret, "POST", timeStamp, nonce, OAuth.OAuthBase.SignatureTypes.HMACSHA1, out str, out str2);
    byte[] image = System.IO.File.ReadAllBytes(path);
    string str6 = this.calculateMD5Hash(image);
    int length = image.Length;
    request = (HttpWebRequest)WebRequest.Create("http://upload.smugmug.com/");
    request.ContentLength = length;
    request.Method = "POST";
    request.Headers.Add("X-Smug-Pretty", "true");

    request.AllowWriteStreamBuffering = false;

    request.ContentType = this.ContentType(Path.GetExtension(path));
    request.Headers["Content-MD5"] = str6;
    request.Headers.Add("Authorization", "OAuth oauth_consumer_key=\"" + this.Smugmug_CONSUMER_KEY + "\",oauth_token=\"" + this.SmugmugAuthToken + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_signature=\"" + HttpUtility.UrlEncode(str5) + "\",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));


    requestStream = request.GetRequestStream();

    int start = 0;
    int chunkSize = 1024 * 100;
    try
    {
    while (start <= length)
    {
    if (start + chunkSize > length)
    requestStream.Write(image, start, length-start);
    else
    requestStream.Write(image, start,chunkSize);
    start += chunkSize;
    double percentage = ((start) / (length * 1.0) ) * 100 ;
    Console.WriteLine("uploading: " + percentage.ToString() + "%");
    }
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.ToString());
    }

    response = (HttpWebResponse)request.GetResponse();

    reader = new StreamReader(response.GetResponseStream());
    string strResult = reader.ReadToEnd().ToUpper();
    Console.WriteLine(DateTime.Now.ToString() + "smugmug >> " + strResult);
    if (strResult.Contains("OK") && strResult.Contains("STAT") && strResult.Contains("METHOD") && strResult.Contains("SMUGMUG.IMAGES.UPLOAD"))
    flag = strResult;
    else
    flag = "";
    Console.WriteLine(DateTime.Now.ToString() + "smugmug UPLOAD in seconds " + DateTime.Now.Subtract(dtS).TotalSeconds.ToString());

    response = (HttpWebResponse)request.GetResponse();

    reader = new StreamReader(response.GetResponseStream());
    string strResult = reader.ReadToEnd().ToUpper();
    Console.WriteLine(DateTime.Now.ToString() + "smugmug >> " + strResult);
    if (strResult.Contains("OK") && strResult.Contains("STAT") && strResult.Contains("METHOD") && strResult.Contains("SMUGMUG.IMAGES.UPLOAD"))
    flag = strResult;
    else
    flag = "";
    Console.WriteLine(DateTime.Now.ToString() + "smugmug UPLOAD in seconds " + DateTime.Now.Subtract(dtS).TotalSeconds.ToString());

    Thanks.
Sign In or Register to comment.