Ejemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------------

        public void SavePic()
        {
            Dictionary <String, String> dic = new Dictionary <String, String>();

            HttpFile postedFile = ctx.GetFileSingle();

            TempUploadFileService uploadService = new TempUploadFileService();
            Result result = uploadService.Upload(postedFile);

            if (result.HasErrors)
            {
                dic.Add("PicUrl", "");
                dic.Add("Msg", result.ErrorsText);
                echoText(Json.ToString(dic));
            }
            else
            {
                TempUploadFile tfile = result.Info as TempUploadFile;

                dic.Add("PicUrl", tfile.FileUrl);
                dic.Add("PicThumbUrl", tfile.FileThumbUrl);
                dic.Add("DeleteLink", to(DeleteTempPic, tfile.Id));

                echoText(Json.ToString(dic));
            }
        }
Ejemplo n.º 2
0
        public void ProcessRequest(System.Web.HttpContext context, NameValueCollection queryString)
        {
            TempUploadFile uploadedFile = null;

            string authCookie = queryString["UserAuthCookie"];

            using (ErrorScope es = new ErrorScope())
            {
                object customResult = null;

                if (authCookie != null)
                {
                    m_OperatorUserId = UserBO.Instance.GetUserID(authCookie, true);

                    string fileName = queryString["filename"];
                    //bool isEmptyFile = context.Request.Form["filesize"] == "0";

                    string action     = queryString["action"];
                    string searchInfo = queryString["key"];

                    uploadedFile = FileManager.Upload(m_OperatorUserId, action, fileName, searchInfo, queryString, ref customResult);
                }

                context.Response.Clear();
                context.Response.StatusCode = 200;

                if (uploadedFile == null)
                {
                    string message = string.Empty;
                    es.CatchError <ErrorInfo>(delegate(ErrorInfo error)
                    {
                        message = error.Message;
                    });

                    context.Response.Write("error|" + message.Replace("|", "|") + "|" + customResult);
                }
                else
                {
                    context.Response.Write(
                        uploadedFile.TempUploadFileID + "|" +
                        uploadedFile.FileName + "|" +
                        uploadedFile.FileSize + "|" +
                        uploadedFile.MD5 + "|" +
                        FileManager.GetExtensionsIcon(uploadedFile.FileName, FileIconSize.SizeOf16) + "|" +
                        FileManager.GetExtensionsIcon(uploadedFile.FileName, FileIconSize.SizeOf32) + "|" +
                        FileManager.GetExtensionsIcon(uploadedFile.FileName, FileIconSize.SizeOf48) + "|" +
                        (customResult == null ? "" : customResult.ToString()));
                }
            }

            if (context.Items.Contains("need-compress"))
            {
                context.Items.Remove("need-compress");
            }
        }
Ejemplo n.º 3
0
        public bool SaveUploadedFile(AuthUser my, int directoryID, int tempFileID, bool replaceExistFile)
        {
            AuthUser user = my;

            if (my == User.Guest)
            {
                ThrowError(new NotLoginError());
                return(false);
            }

            TempUploadFile tempUploadFile = FileManager.GetUserTempUploadFile(my.UserID, tempFileID);

            if (tempUploadFile == null)
            {
                ThrowError(new UnknownError());
                return(false);
            }

            long diskSpace = GetDiskSpaceSize(my.UserID);

            long userRemnantDiskSpace = GetDiskSpaceSize(my.UserID) - user.UsedDiskSpaceSize;

            if (tempUploadFile.FileSize > GetMaxFileSize(my.UserID))
            {
                ThrowError(new DiskFileSizeOverflowError(GetMaxFileSize(my.UserID)));
                return(false);
            }

            if (tempUploadFile.FileSize > userRemnantDiskSpace)
            {
                ThrowError(new InsufficientDiskSpaceError(diskSpace));
                return(false);
            }

            if (DiskDao.Instance.SaveUploadFile(my.UserID, directoryID, tempUploadFile.FileID, tempUploadFile.FileName, tempUploadFile.FileSize, userRemnantDiskSpace, replaceExistFile))
            {
                tempUploadFile.Save();

                //string thumbPath = BuildThumb(tempUploadFile);

                //FileManager.DeleteFiles(canDeleteFileIds);
                CacheUtil.RemoveBySearch(string.Format(cacheKey_diskRoot, my.UserID));
                return(true);
            }
            else
            {
                //if (!string.IsNullOrEmpty(thumbPath))
                //    IOUtil.DeleteFile(thumbPath);
                //saver.Cancel();
                return(false);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Add to temp folder again to delete file
 /// </summary>
 public static async Task RollBackToTempUploadFolderToDelete(Guid id, string container, DatabaseConnectService databaseConnectService, IDbTransaction dbTransaction)
 {
     try
     {
         var file = new TempUploadFile
         {
             Id        = id,
             Container = container,
             CreatedAt = DateTime.UtcNow.AddHours(-3)
         };
         await databaseConnectService.Connection.InsertAsync(file, x => x.AttachToTransaction(dbTransaction));
     }
     catch (Exception e) { }
 }
        private Result Upload( TempUploadFile tfile, User user, IMember owner )
        {
            if (owner != null) {
                tfile.OwnerId = owner.Id;
                tfile.OwnerType = owner.GetType().FullName;
                tfile.OwnerUrl = owner.Url;
            }

            if (user != null) {
                tfile.Creator = user;
                tfile.CreatorUrl = user.Url;
            }

            tfile.Guid = Guid.NewGuid().ToString();

            return db.insert( tfile );
        }
        public virtual Result Upload( HttpFile postedFile, IMember user, IMember owner )
        {
            Result result = Uploader.SaveImg( postedFile );

            if (result.HasErrors) {
                return result;
            }

            String picUrl = strUtil.Join( sys.Path.Photo, result.Info.ToString() );
            String picThumbUrl = Img.GetThumbPath( picUrl );

            String filePath = result.Info.ToString();

            TempUploadFile uploadFile = new TempUploadFile();
            uploadFile.FileSize = postedFile.ContentLength;
            uploadFile.Type = postedFile.ContentType;
            uploadFile.Name = filePath;

            return Upload( uploadFile, (User)user, owner );
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="uploadActionName"></param>
        /// <param name="filename"></param>
        /// <param name="searchInfo"></param>
        /// <param name="customParams"></param>
        /// <returns></returns>
        public static TempUploadFile Upload(int userID, string uploadActionName, string filename, string searchInfo, NameValueCollection queryString, ref object customResult, params string[] customParams)
        {
            if (userID <= 0)
                return null;

            if (searchInfo == null)
                searchInfo = string.Empty;

            FileActionBase uploadAction;
            if (s_UploadActions.TryGetValue(uploadActionName, out uploadAction) == false)
                return null;

            uploadAction = uploadAction.CreateInstance();

            HttpContext context = HttpContext.Current;

            TempUploadFile uploadedFile;

            string tempFileDirectory = Globals.GetPath(SystemDirecotry.Temp_Upload);
            string tempFilename = string.Concat(DateTimeUtil.Now.ToString("yyyy_MM_dd_"), Guid.NewGuid().ToString("N"), Consts.FileSystem_TempFileExtendName);
            string tempFilePath = IOUtil.JoinPath(tempFileDirectory, tempFilename);

            if (!Directory.Exists(tempFileDirectory))
                Directory.CreateDirectory(tempFileDirectory);

            if (uploadAction.BeforeUpload(context, filename, tempFilePath, queryString, ref customResult) == false)
                return null;

            string md5;
            long fileSize;

            //if (1 == 1)
            //{
            //if (context.Request.Files.Count > 0)
            //{
            //HttpPostedFile postedFile = context.Request.Files[0];

            //if (string.IsNullOrEmpty(filename))
            //    filename = postedFile.FileName;

            //fileSize = postedFile.ContentLength;
            //md5 = IOUtil.GetFileMD5Code(postedFile.InputStream);

            //postedFile.SaveAs(tempFilePath);

            FileManagerUploadPolicy uploadPolicy = new FileManagerUploadPolicy(tempFilePath);

            try
            {
                using (FileUploader uploader = new FileUploader(uploadPolicy))
                {
                    uploader.BeginUpload();
                }
            }
            catch(System.Security.SecurityException)// ex)
            {
                using (Stream stream = uploadPolicy.CreateFileStream(context.Request.Files[0].FileName))
                {
                    byte[] buffer = new byte[10240];

                    int readed = 0;

                    while (readed != buffer.Length)
                    {
                        int l = context.Request.Files[0].InputStream.Read(buffer, readed, buffer.Length);

                        stream.Write(buffer, 0, l);

                        readed += l;
                    }
                }
            }

            if (string.IsNullOrEmpty(filename))
                filename = context.Request.Form["filename"];

            if (string.IsNullOrEmpty(filename))
                filename = uploadPolicy.UploadFileName;

            fileSize = uploadPolicy.UploadFileSize;

            md5 = uploadPolicy.UploadFileMD5;

            if (uploadAction.Uploading(context, filename, tempFilePath, fileSize, fileSize, ref customResult) == false)
                return null;

            StringList customParamList = new StringList();
            if (customParams != null)
            {
                foreach (string customParam in customParams)
                    customParamList.Add(customParam);
            }

            uploadedFile = new TempUploadFile(filename, tempFilePath, fileSize, md5);

            uploadedFile.TempUploadFileID = FileDao.Instance.CreateTempUploadFile(userID, uploadActionName, searchInfo, customParamList, filename, tempFilename, md5, fileSize, uploadedFile.FileID);

            //}
            //else
            //    return null;
            //}
            //else
            //{
            //    //Uploader uploader = new Uploader();
            //    //uploader.IsSwfUploader = true;
            //    //if (uploader.BeginUpload(tempFilePath, new Uploader.UploadOnProcess(delegate
            //    //{
            //    //    if (uploadAction.Uploading(filename, tempFilePath, uploader.FileSize, uploader.TotalReceived) == false)
            //    //        return false;

            //    //    return true;
            //    //})))
            //    //{
            //    //    fileSize = uploader.TotalFileReceived;
            //    //    md5 = uploader.MD5Code;

            //    //    uploadedFile = uploader;
            //    //}
            //    //else
            //    //    return null;
            //}

            if (uploadAction.AfterUpload(context, filename, tempFilePath, fileSize, uploadedFile.TempUploadFileID, md5, queryString, ref customResult) == false)
                return null;

            return uploadedFile;
        }
Ejemplo n.º 8
0
        public static PhysicalFileFromTemp Save(int operatorID, TempUploadFile tempUploadFile)
        {
            if (operatorID <= 0)
            {
                Context.ThrowError(new NotLoginError());
                return null;
            }

            if (tempUploadFile == null)
                return null;

            PhysicalFileFromTemp file = FileDao.Instance.SaveFile(operatorID, tempUploadFile.TempUploadFileID);

            string tempUploadFilePath = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Temp_Upload), file.TempUploadServerFileName);
            string targetFilePath = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Upload_File), file.ServerFilePath);

            string targetDirectory = Path.GetDirectoryName(targetFilePath);

            try
            {

                if (File.Exists(targetFilePath))
                    File.Delete(tempUploadFilePath);

                else
                {
                    if (Directory.Exists(targetDirectory) == false)
                        Directory.CreateDirectory(targetDirectory);

                    File.Move(tempUploadFilePath, targetFilePath);
                }

            }
            catch { }

            return file;

        }