private void CreateCompanyMedal() { String[] comapnyNames = { "江苏省扬州市电化教育馆" }; //var winlevelResources = db.CroResourceDal.ConditionQuery(c.Author == "张成娟", null, null, null); var i = 0; foreach (var item in comapnyNames) { //if (i > 10) break; var md5 = string.Empty; var filePath = Server.MapPath("~/Attachments/medal.html"); var htmlStr = System.IO.File.ReadAllText(filePath).Replace("{{Auther}}", item); var fs = MentalConverter.ConverHtmlToImage(htmlStr, item, out md5); using (fs) { if (fs.Length <= 0) { Console.Write($"{item} creat fail"); break; } var docFile = new UploadFile { Stream = fs, FileName = $"2020/files/{DateTime.Today.ToString("yyyyMMdd")}/{md5}{FileHelper.GifExtName}" }; var docResult = FileUploader.SliceUpload(docFile); if (!docResult.IsSuccess) { Console.Write($"{item} mendal upload fail"); break; } } i++; } }
public ActionResult UploadResource() { if (Request.Files.Count != 1) { return(Content("Error")); } HttpPostedFileBase hpf = Request.Files[0]; var md5 = FileHelper.ConvertToMD5(hpf.InputStream); var file = Files.ConditionQuery(f.Md5 == md5, null).FirstOrDefault(); if (file == null) { var ext = Path.GetExtension(hpf.FileName); var anotherName = md5 + ext; // upload file to CDN Server var uploadFile = new UploadFile { Stream = hpf.InputStream, FileName = $"2019/files/{DateTime.Today.ToString("yyyyMMdd")}/{anotherName}" }; var result = FileUploader.SliceUpload(uploadFile); if (null == result || null == result.FileUrl) { return(Content("上传失败")); } if (ext.ToLowerInvariant() == ".doc" || ext.ToLowerInvariant() == ".docx") { Stream docStream = null; try { docStream = Util.ThirdParty.Aspose.WordConverter.ConvertoPdf(hpf.InputStream); var docFile = new UploadFile { Stream = docStream, FileName = $"2019/files/{DateTime.Today.ToString("yyyyMMdd")}/{anotherName}{FileHelper.PdfExtName}" }; var docResult = FileUploader.SliceUpload(docFile); if (null == docResult || null == docResult.FileUrl || !docResult.IsSuccess) { return(Content("word 转pdf失败")); } } catch { } finally { if (docStream != null) { docStream.Close(); docStream.Dispose(); } } } file = new Files { Md5 = md5, FileName = hpf.FileName, FilePath = result.FileUrl, ExtName = ext, FileSize = hpf.ContentLength }; db.FilesDal.Insert(file); } if (Request.IsAjaxRequest()) { return(Json(new { fileId = file.FileId, name = file.FileName, path = file.FilePath, size = file.FileSize, ext = file.ExtName })); } else { return(Content("upload ok")); } }