Esempio n. 1
0
        private BaseUploadFile BaseConvertToUploadFile(BaseUploadFile uploadFile)
        {
            string uploadPhysicalPath = AppSettings.UploadPhysicalPath;
            string uploadVirtualPath  = AppSettings.UploadVirtualPath;

            if (uploadPhysicalPath.IsNullOrWhiteSpace())
            {
                throw new NullReferenceException("config中未配置UploadPhysicalPath");
            }
            if (uploadVirtualPath.IsNullOrWhiteSpace())
            {
                uploadVirtualPath = uploadPhysicalPath.Replace("\\", "/");
            }
            bool isAbsolute = uploadPhysicalPath.IndexOf(":") >= 0;            //如果有:则为绝对路径例如c:\upload\

            uploadPhysicalPath = uploadPhysicalPath.EndsWith("\\") ? uploadPhysicalPath : uploadPhysicalPath + "\\";
            uploadPhysicalPath = isAbsolute ? uploadPhysicalPath : RequestInfos.RootDirectoryPhysicalPath + uploadPhysicalPath;
            isAbsolute         = uploadVirtualPath.IndexOf(".") >= 0;    //如果有.则为绝对网址例如images.xxx.com/
            uploadVirtualPath  = uploadVirtualPath.EndsWith("/") ? uploadVirtualPath : uploadVirtualPath + "/";
            uploadVirtualPath  = isAbsolute && !uploadVirtualPath.StartsWith("http://") ? "http://" + uploadVirtualPath : uploadVirtualPath;

            string subDir = uploadFile.SubDir + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";

            uploadFile.SavePhysicalPath = Path.Combine(uploadPhysicalPath, subDir);
            uploadFile.SaveVirtualPath  = uploadVirtualPath + subDir.Replace("\\", "/");
            return(uploadFile);
        }
Esempio n. 2
0
        private BaseUploadFile ConvertToUploadFile(byte[] file, string ext)
        {
            BaseUploadFile UploadFile   = UploadFileFactory.CreateInstance("", ext);
            MemoryStream   memoryStream = new MemoryStream();

            memoryStream.Write(file, 0, file.Length);
            UploadFile.InputStream   = memoryStream;
            UploadFile.ExtensionName = ext;
            UploadFile.FileName      = Guid.NewGuid() + "." + UploadFile.ExtensionName;
            return(BaseConvertToUploadFile(UploadFile));
        }
Esempio n. 3
0
        private BaseUploadFile ConvertToUploadFile(HttpPostedFileBase file)
        {
            string         ext        = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1);
            BaseUploadFile UploadFile = UploadFileFactory.CreateInstance(file.ContentType, ext);

            UploadFile.OriginalFile  = file;
            UploadFile.InputStream   = file.InputStream;
            UploadFile.ExtensionName = ext;
            UploadFile.FileName      = (this.RandomFileName ? Guid.NewGuid() + "." + UploadFile.ExtensionName : file.FileName);
            UploadFile.FileLength    = file.ContentLength;
            UploadFile.MIMEType      = file.ContentType;
            return(BaseConvertToUploadFile(UploadFile));
        }