コード例 #1
0
ファイル: DocRevHandler.cs プロジェクト: superbee66/dcForm
        /// <summary>
        ///     locate versions of what were once physical files utilizing form/DocTypeName/VersionNumber/*.*
        ///     from archives of what was once seen & now compressed as cab in the document database.
        ///     This allows older documents in the field to request resources that deployed a long time ago
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            // ensure the latest content has been processed & imported
            ImporterController.ImportDocModelsRunOnce();

            //TODO:move ~/web.config ManifestRewrite_Integrated & ManifestRewrite_Classic structures to ~/form/web.config so there is no need for this manifest.xsf httphandler switching logic section to
            if (context.Request.Url.ToString().ToLower().EndsWith("manifest.xsf"))
            {
                new ManifestRewriter().ProcessRequest(context);
            }
            else
            {
                string filename;
                using (MemoryStream _MemoryStream = TemplateController.Instance.OpenRead(context, out filename))
                {
                    context.Response.DisableKernelCache();
                    context.Response.Clear();
                    context.Response.ClearContent();
                    context.Response.ClearHeaders();

                    _MemoryStream.CopyTo(context.Response.OutputStream);

                    context.Response.ContentType = MimeExtensionHelper.GetMimeType(filename);
                    context.Response.AddHeader("content-disposition", "attachment; filename=\"" + filename + "\";");
                }
            }
        }
コード例 #2
0
ファイル: UploadController.cs プロジェクト: afrog33k/eAd
        /// <summary>
        /// Upload a file and return a JSON result
        /// </summary>
        /// <param name="file">The file to upload.</param>
        /// <param name="fileCollection"></param>
        /// <param name="type"> type of upload</param>
        /// <returns>a FileUploadJsonResult</returns>
        /// <remarks>
        /// It is not possible to upload files using the browser's XMLHttpRequest
        /// object. So the jQuery Form Plugin uses a hidden iframe element. For a
        /// JSON response, a ContentType of application/json will cause bad browser
        /// behavior so the content-type must be text/html. Browsers can behave badly
        /// if you return JSON with ContentType of text/html. So you must surround
        /// the JSON in textarea tags. All this is handled nicely in the browser
        /// by the jQuery Form Plugin. But we need to overide the default behavior
        /// of the JsonResult class in order to achieve the desired result.
        /// </remarks>
        /// <seealso cref="http://malsup.com/jquery/form/#code-samples"/>
        //     [Authorize]
        public FileUploadJsonResult AjaxUpload(IEnumerable <HttpPostedFileBase> fileCollection, UploadType type, string uploadPath)
        {
            _type = type;
            // TODO: Add your business logic here and/or save the file
            //System.Threading.Thread.Sleep(2000); // Simulate a long running upload
            // Some browsers send file names with full path. This needs to be stripped.


            //string physicalPath = PathForUpload(file.FileName, 0);


            //// The files are not actually saved in this demo
            //file.SaveAs(physicalPath);
            //lastSavedFile.Add(ResolvePath(physicalPath));
            foreach (string file in Request.Files)
            {
                var      postedFile = Request.Files[file];
                string   thumbPath;
                TimeSpan aduration;
                string   filetype;
                UploadRepository.StoreMediaTemp(HttpContext, postedFile, _type, out thumbPath, out uploadPath, out aduration, out filetype);
                // Return JSON
                if (postedFile != null)
                {
                    if (Request.Url != null)
                    {
                        var result = new FileUploadJsonResult
                        {
                            Data =
                                new
                            {
                                message =
                                    string.Format("Uploaded {0} successfully.", postedFile.FileName),
                                thumbnail        = _path + "/" + thumbPath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty),
                                type             = !String.IsNullOrEmpty(filetype)?filetype : MimeExtensionHelper.FindMime(uploadPath, true),
                                text             = MimeExtensionHelper.FindMime(uploadPath, true).Contains("text") ? thumbPath : "",
                                path             = uploadPath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty),
                                originalFileName = postedFile.FileName,
                                duration         = aduration.ToString()
                            }
                        };
                        return(result);
                    }
                }
            }



            return(new FileUploadJsonResult {
                Data = new { message = "Upload Failed" }
            });
        }
コード例 #3
0
        /// <summary>
        ///     locate versions of what were once physical files utilizing form/DocTypeName/VersionNumber/*.*
        ///     from archives of what was once seen & now compressed as cab in the document database.
        ///     This allows older documents in the field to request resources that deployed a long time ago
        /// </summary>
        /// <param name="context"></param>
        public virtual void ProcessRequest(HttpContext context)
        {
            TemplateFileInfo templatefileinfo;

            using (MemoryStream _MemoryStream = TemplateController.Instance.OpenRead(context, out templatefileinfo))
            {
                context.Response.DisableKernelCache();
                context.Response.Clear();
                context.Response.ClearContent();
                context.Response.ClearHeaders();

                _MemoryStream.CopyTo(context.Response.OutputStream);

                context.Response.ContentType = MimeExtensionHelper.GetMimeType(templatefileinfo.FileName);
                context.Response.AddHeader("content-disposition", "attachment; filename=\"" + templatefileinfo.FileName + "\";");
            }
        }
コード例 #4
0
        protected FileResult DownloadFileAttachment(string fileName, string fileNameHalfPath)
        {
            string fileDownloadName = null;

            var tempF  = fileNameHalfPath.Split('\\');
            int countF = tempF.Length;

            fileDownloadName = tempF[countF - 1];
            fileNameHalfPath = fileNameHalfPath.Replace(@"\\", @"\");
            fileNameHalfPath = fileNameHalfPath.Remove(0, 1);

            string prePathMain            = null;
            string prePathTemp            = null;
            string fileNameServerFullPath = null;

            prePathMain = itemRepo.FindBySettingCd(CommonConstant.SYS_FILE_LOC_MAIN_FOLDER);
            prePathTemp = itemRepo.FindBySettingCd(CommonConstant.SYS_FILE_LOC_TEMP_FOLDER);

            string mainFullPath = Path.Combine(prePathMain, fileNameHalfPath);
            string tempFullPath = Path.Combine(prePathTemp, fileNameHalfPath);

            if (System.IO.File.Exists(mainFullPath))
            {
                fileNameServerFullPath = mainFullPath;
            }
            else
            {
                fileNameServerFullPath = tempFullPath;
            }

            if (!string.IsNullOrEmpty(fileName))
            {
                fileDownloadName = fileName;
            }

            Response.AddHeader("Set-Cookie", "fileDownload=true; path=/");

            return(File(fileNameServerFullPath, MimeExtensionHelper.GetMimeType(fileDownloadName),
                        fileDownloadName));
        }
コード例 #5
0
        //protected void SendToClientBrowser(string fileName, byte[] hasil)
        //{
        //    Response.Clear();
        //    //Response.ContentType = result.MimeType;
        //    Response.Cache.SetCacheability(HttpCacheability.Private);
        //    Response.Expires = -1;
        //    Response.Buffer = true;

        //    Response.ContentType = "application/octet-stream";
        //    Response.AddHeader("Content-Length", Convert.ToString(hasil.Length));

        //    Response.AddHeader("Content-Disposition", string.Format("{0};FileName=\"{1}\"", "attachment", fileName));
        //    Response.AddHeader("Set-Cookie", "fileDownload=true; path=/");

        //    Response.BinaryWrite(hasil);
        //    Response.End();
        //}

        // Summary:
        //     Handle Download File Request
        //
        // Parameters:
        //     fileName : the filename to be download
        //     paths : list path will be search the file
        //     fileDownloadName : the filename to be send to browser
        protected FileResult DownloadFile(string fileName, IList <string> paths, string fileDownloadName)
        {
            string fileNameServerFullPath = null;

            foreach (string path in paths)
            {
                fileNameServerFullPath = Path.Combine(path, fileName);

                if (System.IO.File.Exists(fileNameServerFullPath))
                {
                    break;
                }
            }

            if (string.IsNullOrEmpty(fileDownloadName))
            {
                fileDownloadName = fileName;
            }

            Response.AddHeader("Set-Cookie", "fileDownload=true; path=/");

            return(File(fileNameServerFullPath, MimeExtensionHelper.GetMimeType(fileDownloadName),
                        fileDownloadName));/*MimeMapping.GetMimeMapping(fileName)*/
        }
コード例 #6
0
 protected BaseSmartImageAnalyzer(BlobService blobService, IImageResizer imageResizer, MimeExtensionHelper mimeExtensionHelper)
 {
     _blobService         = blobService;
     _imageResizer        = imageResizer;
     _mimeExtensionHelper = mimeExtensionHelper;
 }
 public GoogleSmartImageAnalyzer(BlobService blobService, IImageResizer imageResizer, MimeExtensionHelper mimeExtensionHelper)
     : base(blobService, imageResizer, mimeExtensionHelper)
 {
 }
コード例 #8
0
 private void DecodeBase64Img(string input)
 {
     new Thread(() =>
     {
         var regex = new Regex(@"data:(?<mime>[\w/\-\.]+);(?<encoding>\w+),(?<data>.*)", RegexOptions.Compiled);
         MatchCollection collection = regex.Matches(input);
         if (collection == null)
         {
             return;
         }
         {
             foreach (Match match in collection)
             {
                 var mime     = match.Groups["mime"].Value;
                 var encoding = match.Groups["encoding"].Value;
                 var data     = match.Groups["data"].Value;
                 var filePath = Path.Combine("", Guid.NewGuid().ToString("N") + MimeExtensionHelper.GetExtension(mime));
                 File.WriteAllBytes(filePath, Convert.FromBase64String(data));
             }
         }
     }).Start();
 }