コード例 #1
0
ファイル: PhotoReceiver.ashx.cs プロジェクト: ktei/MySpace
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                // Prepare parameters
                UploadParameters parameters = GetParametersFromRequest(context);
                if (!VerifyTicket(parameters.RequestToken, parameters.Ticket))
                {
                    throw new Exception("No valid ticket for this request was found.");
                }

                // Check request content length and actual stream length
                // If they're not equal, it means the client canceled the uploading
                bool lengthsMatched = context.Request.ContentLength == context.Request.InputStream.Length;
                if (!lengthsMatched)
                {
                    return;
                }

                var    storage     = SharpBoxSupport.OpenDropBoxStorage();
                var    newFileName = ObjectId.GenerateNewId() + parameters.FileExtension;
                string downloadURI = UploadDownlaodable(context, storage, newFileName, parameters.AlbumId);
                string photoURI    = UploadPhoto(context, storage, newFileName, parameters.AlbumId);
                string thumbURI    = UploadThumbnail(context, storage, newFileName, parameters.AlbumId);
                storage.Close();

                string[] coverURIs = AlbumRepository.UpdateCover(parameters.AlbumId, thumbURI);
                Photo    photo     = new Photo()
                {
                    PhotoURI    = photoURI,
                    ThumbURI    = thumbURI,
                    DownloadURI = downloadURI,
                    AlbumId     = parameters.AlbumId,
                    CreatedBy   = parameters.User
                };
                PhotoRepository.CreatePhoto(photo);
                context.Response.Write(string.Join(";", coverURIs));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                context.Request.InputStream.Close();
                context.Response.Write("error");
            }
        }