Ejemplo n.º 1
0
        public override void OnProcessRequest(HttpContext context)
        {
            try
            {
                var storeDomain = context.Request["esid"];
                var itemID      = context.Request["iid"] ?? "";

                var file = context.Request.Files["NewFile"];

                if (file.ContentLength > SetupInfo.MaxImageUploadSize)
                {
                    SendFileUploadResponse(context, 1, true, string.Empty, string.Empty, FileSizeComment.FileImageSizeExceptionString);
                    return;
                }

                var filename = file.FileName.Replace("%", string.Empty);
                var ind      = file.FileName.LastIndexOf("\\");
                if (ind >= 0)
                {
                    filename = file.FileName.Substring(ind + 1);
                }
                var folderID = CommonControlsConfigurer.FCKAddTempUploads(storeDomain, filename, itemID);

                var store   = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "fckuploaders");
                var saveUri = store.Save(storeDomain, folderID + "/" + filename, file.InputStream).ToString();

                SendFileUploadResponse(context, 0, true, saveUri, filename, string.Empty);
            }
            catch (Exception e)
            {
                SendFileUploadResponse(context, 1, true, string.Empty, string.Empty, e.Message.HtmlEncode());
            }
        }
        private static void NewProcessRequest(HttpContext context)
        {
            try
            {
                var funcNum     = context.Request["CKEditorFuncNum"];
                var storeDomain = context.Request["esid"];
                var itemID      = context.Request["iid"] ?? "";
                var file        = context.Request.Files["upload"];

                if (file.ContentLength > SetupInfo.MaxImageUploadSize)
                {
                    NewSendFileUploadResponse(context, string.Empty, funcNum, FileSizeComment.FileImageSizeExceptionString);
                    return;
                }

                var filename = file.FileName;

                var ind = filename.LastIndexOf("\\", StringComparison.Ordinal);
                if (ind >= 0)
                {
                    filename = filename.Substring(ind + 1);
                }

                filename = new Regex("[\t*\\+:\"<>#%&?|\\\\/]").Replace(filename, "_");

                if (FileUtility.GetFileTypeByFileName(filename) != FileType.Image)
                {
                    NewSendFileUploadResponse(context, string.Empty, funcNum, Resource.ErrorUnknownFileImageType);
                    return;
                }

                var folderID = CommonControlsConfigurer.FCKAddTempUploads(storeDomain, filename, itemID);

                var store   = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "fckuploaders");
                var saveUri = store.Save(storeDomain, folderID + "/" + filename, file.InputStream).ToString();

                NewSendFileUploadResponse(context, saveUri, funcNum, string.Empty);
            }
            catch (Exception e)
            {
                NewSendFileUploadResponse(context, string.Empty, string.Empty, e.Message.HtmlEncode());
            }
        }