Options

What is the most efficient API method for uploading a 32GB video to SmugMug?

ckelleyckelley Registered Users Posts: 26 Big grins
I've developed a front end that enables authenticated users to upload images and videos by dragging-and-dropping them onto an ASP.NET web page. Based on a couple menu selections on that page, the appropriate SmugMug gallery is created and/or targeted. The uploaded files are saved to temp files on our server before they are uploaded from our servers to SmugMug. We decided to upload the files to our servers first for the following reasons:
  • When I first started the project, I understood neither the open source front-end nor the SmugMug API. This architecture allowed me to postponed my deep-dive into the SmugMug API and still make progress.
  • SmugMug sometime takes a couple minutes to produce a thumbnail image after a file is uploaded. Our architecture enables us to derive a temporary thunbnail on our server to provide more immediate feedback to the user.
  • I'm still not sure how to call the SmugMug API from javascript. But, I'm not sure we could do so without exposing our SmugMug security credentials to a sophisticated end user.

As of this writing, I am using API 1.2.2 to upload files from our servers to SmugMug as follows:
        public Image UploadImage(string sessionId, string path, IdType albumId, string albumKey, string caption, string keywords, IUploadProgress callback)
        {
            Require.NotNullOrEmpty(sessionId, "sessionId");

            FileInfo info = new FileInfo(path);
            if (!info.Exists)
            {
                throw new ArgumentException("Image does not exist: " + info.FullName);
            }
            using (FileStream stream = File.OpenRead(info.FullName))
            {
                UploadContext context = GetUploadContext(sessionId, stream, path, albumId, albumKey, caption, keywords);
                //Logger.Info("Uploading {0} ({1} bytes)", path, stream.Length);
                // context.ChunkSize = Math.Max((int)(context.PhotoStream.Length / 100), 65536)
                while (UploadChunk(context))
                {
                    //Logger.Info("{0}% complete", context.PercentComplete);
                    if (callback != null)
                    {
                        callback.SetProgress(context.PercentComplete);

                        if (callback.Canceled)
                        {
                            //Logger.Warn("Upload Cancelled");
                            return null;
                        }
                    }
                }
                //Logger.Info("Upload Complete");
                context.RequestStream.Close();
                context.RequestStream.Dispose();

                WebResponse httpResponse = context.Request.GetResponse();
                using (StreamReader reader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    string result = reader.ReadToEnd();
                    reader.Close();
                    reader.Dispose();
                    httpResponse.Close();

                    //Logger.Info(result);

                    var response = protocol.GetResponse<Image>(result);
                    if (response.Error != null)
                    {
                        SmugmugException exception = new SmugmugException((FaultCode)response.Error.ErrorCode);
                        if (callback != null)
                            callback.Error(exception);
                        else
                            throw exception;
                    }
                    if (callback != null)
                        callback.Completed(response.Data);
                    return response.Data;
                }
            }
        }

The only major drawback to this approach is that the project bar displayed to users during the upload is close to 100% when the upload to SmugMug is just getting started.

Here are my questions:
  1. What is the optimal chunk size for SmugMug?
  2. How can the efficiency of the method above be improved?
  3. What other method would be more efficient than the above?
  4. Can you point me to an example where chunked SmugMug upload is invoked from Javascript that would not expose our SmugMug security credentials?
I have to finish this by 31 May 2014 at the latest. So, I don't have time to wait for API 2.0. I assume that means I must use API 1.2.2 or 1.3.
Sign In or Register to comment.