public JsonResult UploadExcel(int packageId, Guid ruleGUID) { var files = Request.Files; var convertResult = ConvertExcelToList(files); var data = new List <BaoYangPackagePromotionDetail>(); var flag = false; if (!string.IsNullOrEmpty(convertResult.Item2)) { return(Json(new { status = false, msg = convertResult.Item2 })); } var manager = new VipBaoYangPackageManager(); var validated = manager.ValidatedUploadData(ruleGUID, convertResult.Item1); if (!validated.Item1) { return(Json(new { status = false, msg = validated.Item2 })); } var extension = Path.GetExtension(files[0].FileName); var uploadResult = new UploadFileManager().UploadFile(convertResult.Item4, FileType.VipBaoYangPackage, extension, files[0].FileName, HttpContext.User.Identity.Name); if (!string.IsNullOrEmpty(uploadResult.Item1) && !string.IsNullOrEmpty(uploadResult.Item2)) { flag = manager.BatchBaoYangPakckagePromotion(packageId, ruleGUID, convertResult.Item3, uploadResult.Item2, HttpContext.User.Identity.Name); if (flag) { data = convertResult.Item1; } } return(Json(new { status = flag, data = data })); }
public void CancelUploading(TLDecryptedMessageMediaBase media) { var mediaPhoto = media as TLDecryptedMessageMediaPhoto; if (mediaPhoto != null && mediaPhoto.File != null) { var file = mediaPhoto.File as TLEncryptedFile; if (file != null && file.Id != null) { UploadFileManager.CancelUploadFile(file.Id); } } var mediaDocument = media as TLDecryptedMessageMediaDocument; if (mediaDocument != null && mediaDocument.File != null) { var file = mediaDocument.File as TLEncryptedFile; if (file != null && file.Id != null) { UploadDocumentFileManager.CancelUploadFile(file.Id); } } var mediaVideo = media as TLDecryptedMessageMediaVideo; if (mediaVideo != null && mediaVideo.File != null) { var file = mediaVideo.File as TLEncryptedFile; if (file != null && file.Id != null) { UploadVideoFileManager.CancelUploadFile(file.Id); } } }
public ActionResult UploadTempImportFile(HttpPostedFileBase file) { if (file == null) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } string message = string.Empty; try { string fileSize = FileOperateHelper.FileSize(file.ContentLength); string fileType = Path.GetExtension(file.FileName); //保存文件 UploadFileManager.httpContext = _Request.RequestContext.HttpContext; string filePath = UploadFileManager.SaveAs(file, string.Empty, "Temp"); if (string.IsNullOrWhiteSpace(filePath)) { message = "上传失败!"; } return(Json(new { Success = string.IsNullOrEmpty(message), Message = message, FilePath = filePath }, "text/plain")); } catch (Exception ex) { message = string.Format("上传失败,异常:{0}", ex.Message); return(Json(new ReturnResult { Success = false, Message = message }, "text/plain")); } }
public JsonResult UpdateFileTaskStatus(string batchCode) { var manager = new UploadFileManager(); var result = manager.UpdateFileTaskStatus(batchCode, FileType.VipBaoYangPackage, FileStatus.Repaired, FileStatus.WaitingForRepair); return(Json(new { status = result })); }
public FolderContentService() { var endpoint = OperationContext.Current.EndpointDispatcher.EndpointAddress.ToString(); var userId = endpoint.Split('/').Last(); var configuration = ClientConfiguration.Instance.GetConfiguration(userId); _folderContentManager = new CacheFolderContentManager(configuration); _folderContentSearchManager = new FolderContentSearchManager(configuration); _uploadFileManager = new UploadFileManager(configuration); }
/// <summary> /// 上传文件 /// </summary> /// <param name="upfile">上传的文件</param> /// <param name="configName">配置名称</param> /// <param name="dir">保存的文件夹</param> /// <returns>保存路径</returns> private string UploadFile(HttpPostedFileBase upfile, string configName, string dir) { if (_Request == null) { _Request = Request; } string filePath = string.IsNullOrWhiteSpace(dir) ? "Other" : dir; string path = UploadFileManager.SaveAs(upfile, configName, filePath); return(path); }
private void UploadPhotoInternal(IList <TLMessage> messages) { for (var i = 0; i < messages.Count; i++) { var message = messages[i]; var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; UploadFileManager.UploadFile(fileId, message, message.Media.File); } }
private void SendPhotoInternal(IList <TLMessage> messages) { //if (messages.Count == 3) //{ // SendPhotoInternal((TLMessage25)messages[1]); // SendPhotoInternal((TLMessage25)messages[0]); // SendPhotoInternal((TLMessage25)messages[2]); //} //else { for (var i = 0; i < messages.Count; i++) { var message = messages[i]; //var photo = ((TLMessageMediaPhoto)message.Media).Photo as TLPhoto; //if (photo == null) return; //var photoSize = photo.Sizes[0] as TLPhotoSize; //if (photoSize == null) return; //var fileLocation = photoSize.Location; //if (fileLocation == null) return; //byte[] bytes = null; //var fileName = String.Format("{0}_{1}_{2}.jpg", // fileLocation.VolumeId, // fileLocation.LocalId, // fileLocation.Secret); //using (var store = IsolatedStorageFile.GetUserStoreForApplication()) //{ // using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) // { // if (fileStream.Length > 0) // { // bytes = new byte[fileStream.Length]; // fileStream.Read(bytes, 0, bytes.Length); // } // } //} //if (bytes == null) return; var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; UploadFileManager.UploadFile(fileId, message, message.Media.File); //SendPhotoInternal((TLMessage25)messages[i]); } } }
private void SendAudioInternal(TLObject obj) { var message = GetDecryptedMessage(obj); if (message == null) { return; } var media = message.Media as TLDecryptedMessageMediaAudio; if (media == null) { return; } var fileLocation = media.File as TLEncryptedFile; if (fileLocation == null) { return; } var fileName = String.Format("audio{0}_{1}.mp3", fileLocation.Id, fileLocation.AccessHash); byte[] data; using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) { data = new byte[fileStream.Length]; fileStream.Read(data, 0, data.Length); } } var encryptedBytes = Telegram.Api.Helpers.Utils.AesIge(data, media.Key.Data, media.IV.Data, true); using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var file = storage.OpenFile("encrypted." + fileName, FileMode.Create, FileAccess.Write)) { file.Write(encryptedBytes, 0, encryptedBytes.Length); } } UploadFileManager.UploadFile(fileLocation.Id, obj, encryptedBytes); }
IEnumerator UploadUserData() { PopupManager.instance.SetLoading(true); UploadFileManager.AddFileName(ZipFileName); WWWForm form = new WWWForm(); string path = Application.persistentDataPath + "/Zips/" + ZipFileName + ".zip"; byte[] bytes = File.ReadAllBytes(path); form.AddField("user_id", LoginManager.UserID); form.AddBinaryData("file", bytes, ZipFileName + ".zip");; UnityWebRequest webRequest = UnityWebRequest.Post("http://shopanalytica.com/public/api/save-zip-file", form); webRequest.SendWebRequest(); while (!webRequest.isDone) { yield return(null); // Progress is always set to 1 on android //progressText.text = webRequest.uploadProgress*100+"%"; //progressFill.fillAmount = webRequest.uploadProgress; progressText.text = "Uploading..."; progressFill.fillAmount = 0; } if (webRequest.isHttpError || webRequest.isNetworkError) { Debug.Log(webRequest.error); PopupManager.instance.OpenPopup("Upload Failed!"); PopupManager.instance.SetLoading(false); } else { Debug.Log("Request Done!:" + webRequest.downloadHandler.text); loadingObject.SetActive(false); //UploadFileManager.RemoveDoneFileName(ZipFileName); PopupManager.instance.OpenPopup("Upload Done!"); PopupManager.instance.SetLoading(false); // ShopData.ShopDataManager.CurrentDayShopInfo = "UnLoaded"; } }
private void UploadPhotoInternal(byte[] data, TLObject obj) { var message = GetDecryptedMessage(obj); if (message == null) { return; } var media = message.Media as TLDecryptedMessageMediaPhoto; if (media == null) { return; } var file = media.File as TLEncryptedFile; if (file == null) { return; } if (data == null) { var fileName = String.Format("{0}_{1}_{2}.jpg", file.Id, file.DCId, file.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) { data = new byte[fileStream.Length]; fileStream.Read(data, 0, data.Length); } } } var encryptedBytes = Telegram.Api.Helpers.Utils.AesIge(data, media.Key.Data, media.IV.Data, true); UploadFileManager.UploadFile(file.Id, obj, encryptedBytes); }
public ActionResult ImageManager(string action) { string[] paths = { "Image", "Other" }; //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时 string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" }; String str = String.Empty; if (_Request == null) { _Request = Request; } if (action == "get") { UploadFileManager.httpContext = _Request.RequestContext.HttpContext; foreach (string path in paths) { var cfg = UploadFileManager.GetUploadConfig("UEImage"); string basePath = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/" + path; if (WebConfigHelper.GetAppSettingValue("IsLinux") != "true") { basePath = basePath.Replace("/", "\\"); } DirectoryInfo info = new DirectoryInfo(basePath); //目录验证 if (info.Exists) { DirectoryInfo[] infoArr = info.GetDirectories(); foreach (DirectoryInfo tmpInfo in infoArr) { foreach (FileInfo fi in tmpInfo.GetFiles()) { if (Array.IndexOf(filetype, fi.Extension) != -1) { str += cfg.Folder + "/" + path + "/" + tmpInfo.Name + "/" + fi.Name + "ue_separate_ue"; } } } } } } return(Content(str)); }
public ActionResult UploadTempImage(HttpPostedFileBase file) { if (file == null) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } string message = string.Empty; string imgName = _Request["imgName"].ObjToStr(); try { string fileSize = FileOperateHelper.FileSize(file.ContentLength); string fileType = Path.GetExtension(file.FileName); //保存文件 UploadFileManager.httpContext = _Request.RequestContext.HttpContext; string filePath = UploadFileManager.SaveAs(file, string.Empty, "Temp", imgName); if (!string.IsNullOrEmpty(filePath) && filePath.Substring(0, 1) != "/") { filePath = "/" + filePath; } else { message = "临时图片保存失败!"; } return(Json(new { Success = string.IsNullOrEmpty(message), Message = message, FilePath = filePath }, "text/plain")); } catch (Exception ex) { message = string.Format("图片上传失败,原因:{0}", ex.Message); return(Json(new ReturnResult { Success = false, Message = message }, "text/plain")); } }
public ActionResult ImageManager(string action) { string[] paths = { "Image", "Other" }; //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时 string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" }; String str = String.Empty; if (_Request == null) { _Request = Request; } if (action == "get") { string pathFlag = System.IO.Path.DirectorySeparatorChar.ToString(); foreach (string path in paths) { var cfg = UploadFileManager.GetUploadConfig("UEImage"); string basePath = WebHelper.MapPath("/") + pathFlag + cfg.Folder + pathFlag + path; DirectoryInfo info = new DirectoryInfo(basePath); //目录验证 if (info.Exists) { DirectoryInfo[] infoArr = info.GetDirectories(); foreach (DirectoryInfo tmpInfo in infoArr) { foreach (FileInfo fi in tmpInfo.GetFiles()) { if (Array.IndexOf(filetype, fi.Extension) != -1) { str += cfg.Folder + "/" + path + "/" + tmpInfo.Name + "/" + fi.Name + "ue_separate_ue"; } } } } } } return(Content(str)); }
public ActionResult UploadAttachment(HttpPostedFileBase[] file, Guid?moduleId, Guid?id, bool isCreateSwf = false) { if (file == null || file.Where(o => o == null).Count() > 0) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } SetRequest(_Request); string attachType = _Request["attachType"].ObjToStr(); UploadFileManager.httpContext = _Request.RequestContext.HttpContext; string message = string.Empty; StringBuilder msg = new StringBuilder(); List <AttachFileInfo> fileMsg = new List <AttachFileInfo>(); foreach (var item in file) { try { string fileSize = FileOperateHelper.FileSize(item.ContentLength); string fileType = Path.GetExtension(item.FileName); string fileName = item.FileName; string pathFlag = "\\"; if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true") { pathFlag = "/"; } int s = fileName.LastIndexOf(pathFlag); if (s >= 0) { fileName = fileName.Substring(s + 1); } //保存文件 string filePath = string.Empty; if (moduleId.HasValue) //表单附件 { filePath = UploadFileManager.SaveAs(item, "Attachment", "Temp"); } else { filePath = UploadFileManager.SaveAs(item, string.Empty); } filePath = filePath.StartsWith("~/") ? filePath : filePath.StartsWith("/") ? "~" + filePath : "~/" + filePath; //swf保存路径 string swfPath = string.Empty; //pdf保存路径 string pdfPath = string.Empty; if (isCreateSwf && !moduleId.HasValue) { //exe路径 string exePath = _Request.RequestContext.HttpContext.Server.MapPath("~/bin/SWFTools/pdf2swf.exe"); //bin路径 string binPath = _Request.RequestContext.HttpContext.Server.MapPath("~/bin/"); if (fileType.Equals(".doc") || fileType.Equals(".docx") || fileType.Equals(".xls") || fileType.Equals(".xlsx") || fileType.Equals(".ppt") || fileType.Equals(".pptx") || fileType.Equals(".pdf")) { //取pdf和swf路径 GetFilePath(out pdfPath, out swfPath); //参数 string[] obj = new string[] { fileType, _Request.RequestContext.HttpContext.Server.MapPath(filePath), _Request.RequestContext.HttpContext.Server.MapPath(pdfPath), _Request.RequestContext.HttpContext.Server.MapPath(swfPath), exePath, binPath }; CreateSwfFile(obj); } } fileMsg.Add(new AttachFileInfo() { AttachFile = filePath, PdfFile = pdfPath, SwfFile = swfPath, FileName = fileName, FileType = fileType, FileSize = fileSize, AttachType = attachType }); } catch (Exception ex) { msg.AppendLine(item.FileName + "上传失败:" + ex.Message); break; } } if (moduleId.HasValue && id.HasValue) //查看页面,直接保存附件 { return(SaveFormAttach(moduleId.Value, id.Value, JsonHelper.Serialize(fileMsg), true)); } return(Json(new { Success = string.IsNullOrEmpty(msg.ToString()), Message = string.IsNullOrEmpty(msg.ToString()) ? "上传成功" : msg.ToString(), FileMsg = fileMsg.Count > 0 ? JsonHelper.Serialize(fileMsg) : string.Empty }, "text/plain")); }
public ActionResult ScrawlUp(HttpPostedFileBase upfile, string content) { if (_Request == null) { _Request = Request; } UploadFileManager.httpContext = _Request.RequestContext.HttpContext; var cfg = UploadFileManager.GetUploadConfig("UEImage"); if (upfile != null) { string path = string.Empty; string state = "SUCCESS"; //上传图片 try { path = UploadFile(upfile, "UEImage", "Temp"); } catch (Exception ex) { return(Json(new { state = ex.Message })); } return(Content("<script>parent.ue_callback('" + path + "','" + state + "')</script>"));//回调函数 } else { //上传图片 string url = string.Empty; string state = "SUCCESS"; FileStream fs = null; string pathFlag = "\\"; if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true") { pathFlag = "/"; } try { string dir = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/Other"; string path = DateTime.Now.ToString("yyyyMM"); dir = dir + "/" + path; if (pathFlag == "\\") { dir = dir.Replace("/", "\\"); } if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string filename = System.Guid.NewGuid() + ".png"; fs = System.IO.File.Create(dir + pathFlag + filename); byte[] bytes = Convert.FromBase64String(content); fs.Write(bytes, 0, bytes.Length); url = cfg.Folder + "/Other/" + path + "/" + filename; } catch (Exception e) { state = "未知错误:" + e.Message; url = ""; } finally { fs.Close(); string tempDir = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/Temp"; if (pathFlag == "\\") { tempDir = tempDir.Replace("/", "\\"); } DirectoryInfo info = new DirectoryInfo(tempDir); if (info.Exists) { DirectoryInfo[] infoArr = info.GetDirectories(); foreach (var item in infoArr) { string str = tempDir + pathFlag + item.Name; Directory.Delete(str, true); } } } return(Json(new { url = url, state = state })); } }
private void SendCompressedVideoInternal(TLMessage message, object o) #endif { var documentMedia = message.Media as TLMessageMediaDocument45; if (documentMedia != null) { var fileName = documentMedia.IsoFileName; if (string.IsNullOrEmpty(fileName)) { return; } var video = documentMedia.Document as TLDocument22; if (video == null) { return; } byte[] thumbBytes = null; var photoThumb = video.Thumb as TLPhotoSize; if (photoThumb != null) { var location = photoThumb.Location as TLFileLocation; if (location == null) { return; } var thumbFileName = String.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret); using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var thumbFile = storage.OpenFile(thumbFileName, FileMode.Open, FileAccess.Read)) { thumbBytes = new byte[thumbFile.Length]; thumbFile.Read(thumbBytes, 0, thumbBytes.Length); } } } var fileId = message.Media.FileId ?? TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; //return; #if WP81 if (file != null) { UploadVideoFileManager.UploadFile(fileId, message.IsGif(), message, file); } else if (!string.IsNullOrEmpty(fileName)) { UploadVideoFileManager.UploadFile(fileId, message, fileName); } else { return; } #else UploadVideoFileManager.UploadFile(fileId, message, fileName); #endif if (thumbBytes != null) { var fileId2 = TLLong.Random(); UploadFileManager.UploadFile(fileId2, message.Media, thumbBytes); } return; } var videoMedia = message.Media as TLMessageMediaVideo; if (videoMedia != null) { var fileName = videoMedia.IsoFileName; if (string.IsNullOrEmpty(fileName)) { return; } var video = videoMedia.Video as TLVideo; if (video == null) { return; } byte[] thumbBytes = null; var photoThumb = video.Thumb as TLPhotoSize; if (photoThumb != null) { var location = photoThumb.Location as TLFileLocation; if (location == null) { return; } var thumbFileName = String.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret); using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var thumbFile = storage.OpenFile(thumbFileName, FileMode.Open, FileAccess.Read)) { thumbBytes = new byte[thumbFile.Length]; thumbFile.Read(thumbBytes, 0, thumbBytes.Length); } } } var fileId = message.Media.FileId ?? TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; #if WP81 if (file != null) { UploadVideoFileManager.UploadFile(fileId, message.IsGif(), message, file); } else if (!string.IsNullOrEmpty(fileName)) { UploadVideoFileManager.UploadFile(fileId, message, fileName); } else { return; } #else UploadVideoFileManager.UploadFile(fileId, message, fileName); #endif if (thumbBytes != null) { var fileId2 = TLLong.Random(); UploadFileManager.UploadFile(fileId2, message.Media, thumbBytes); } return; } }
public ActionResult UploadExcel(int packageId, Guid ruleGuid) { var result = false; if (packageId <= 0 || ruleGuid == Guid.Empty) { return(Json(new { Status = false, Msg = "未知的对象" })); } var files = Request.Files; if (files.Count < 1) { return(Json(new { Status = false, Msg = "请选择文件" })); } var file = files[0]; if (file.ContentType != "application/vnd.ms-excel" && file.ContentType != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { return(Json(new { Status = false, Msg = "请上传Excel文件" })); } var manager = new VipPaintPackageManager(); var isExist = manager.IsExistVipPaintFile(file.FileName); if (isExist) { return(Json(new { Status = false, Msg = $"{file.FileName}已导入成功,请勿重复导入" }, JsonRequestBehavior.AllowGet)); } var convertResult = ConvertExcelToList(file); if (!string.IsNullOrEmpty(convertResult.Item2)) { return(Json(new { Status = false, Msg = convertResult.Item2 })); } else if (convertResult.Item1 == null || !convertResult.Item1.Any()) { return(Json(new { Status = false, Msg = "Excel内容为空" })); } var validResult = manager.ValidatedUploadData(ruleGuid, convertResult.Item1); if (!validResult.Item1) { return(Json(new { Status = false, Msg = string.IsNullOrEmpty(validResult.Item2) ? "优惠券规则验证失败" : validResult.Item2 })); } #region 文件到服务器 var extension = Path.GetExtension(file.FileName); var stream = file.InputStream; var buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); stream.Position = 0; var uploadResult = new UploadFileManager().UploadFile(buffer, FileType.VipPaintPackage, extension, file.FileName, User.Identity.Name); #endregion //上传服务器成功插入一条塞券记录 if (!string.IsNullOrEmpty(uploadResult.Item1) && !string.IsNullOrEmpty(uploadResult.Item2)) { var isSendSms = manager.IsPackageSms(packageId); var model = new VipPaintPackagePromotionRecordModel() { PackageId = packageId, BatchCode = uploadResult.Item2, RuleGUID = ruleGuid, IsSendSms = isSendSms, ToBOrder = string.Empty, CreateUser = User.Identity.Name }; result = manager.InsertPromotionRecord(model); } return(Json(new { Status = result, Msg = result ? "上传成功" : "上传失败" }, JsonRequestBehavior.AllowGet)); }
private void SendDocumentInternal(TLMessage25 message, object o) #endif { var document = ((TLMessageMediaDocument)message.Media).Document as TLDocument; if (document == null) { return; } byte[] thumbBytes = null; var thumb = document.Thumb as TLPhotoSize; if (thumb != null) { var thumbLocation = thumb.Location as TLFileLocation; if (thumbLocation != null) { var fileName = String.Format("{0}_{1}_{2}.jpg", thumbLocation.VolumeId, thumbLocation.LocalId, thumbLocation.Secret); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) { thumbBytes = new byte[fileStream.Length]; fileStream.Read(thumbBytes, 0, thumbBytes.Length); } } } } var bytes = document.Buffer; var md5Bytes = Telegram.Api.Helpers.Utils.ComputeMD5(bytes ?? new byte[0]); var md5Checksum = BitConverter.ToInt64(md5Bytes, 0); StateService.GetServerFilesAsync( results => { var serverFile = results.FirstOrDefault(result => result.MD5Checksum.Value == md5Checksum); if (serverFile != null) { message.InputMedia = serverFile.Media; ShellViewModel.SendMediaInternal(message, MTProtoService, StateService, CacheService); } else { if (thumbBytes != null) { var thumbFileId = TLLong.Random(); UploadFileManager.UploadFile(thumbFileId, message.Media, thumbBytes); Thread.Sleep(100); //NOTE: без этой строки не работает. Почему??? } var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; #if WP81 if (file == null) { UploadDocumentFileManager.UploadFile(fileId, message, bytes); } else { UploadDocumentFileManager.UploadFile(fileId, message, file); } #else UploadDocumentFileManager.UploadFile(fileId, message, bytes); #endif } }); }
public ActionResult GetFileTaskStatus(string batchcode) { var result = new UploadFileManager().GetFileTaskStatus(batchcode, FileType.VipBaoYangPackage); return(Json(new { data = result }, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateFileTaskStatus(string batchCode) { var result = new UploadFileManager().UpdateFileTaskStatus(batchCode, FileType.VipPaintPackage, FileStatus.Repaired, FileStatus.WaitingForRepair); return(Json(new { Status = result, Msg = $"操作{(result ? "成功" : "失败")}" })); }
private void UploadPhotoInternal(TLMessage34 message) { var photo = ((TLMessageMediaPhoto)message.Media).Photo as TLPhoto; if (photo == null) { return; } var photoSize = photo.Sizes[0] as TLPhotoSize; if (photoSize == null) { return; } var fileLocation = photoSize.Location; if (fileLocation == null) { return; } byte[] bytes = null; var fileName = String.Format("{0}_{1}_{2}.jpg", fileLocation.VolumeId, fileLocation.LocalId, fileLocation.Secret); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) { if (fileStream.Length > 0) { bytes = new byte[fileStream.Length]; fileStream.Read(bytes, 0, bytes.Length); } } } if (bytes == null) { return; } var md5Bytes = Telegram.Api.Helpers.Utils.ComputeMD5(bytes); var md5Checksum = BitConverter.ToInt64(md5Bytes, 0); StateService.GetServerFilesAsync( results => { var serverFile = results.FirstOrDefault(result => result.MD5Checksum.Value == md5Checksum); #if MULTIPLE_PHOTOS serverFile = null; #endif if (serverFile != null) { var media = serverFile.Media; var captionMedia = media as IInputMediaCaption; if (captionMedia == null) { var inputMediaPhoto = serverFile.Media as TLInputMediaPhoto; if (inputMediaPhoto != null) { var inputMediaPhoto75 = new TLInputMediaPhoto75(inputMediaPhoto); captionMedia = inputMediaPhoto75; media = inputMediaPhoto75; serverFile.Media = inputMediaPhoto75; StateService.SaveServerFilesAsync(results); } var inputMediaUploadedPhoto = serverFile.Media as TLInputMediaUploadedPhoto; if (inputMediaUploadedPhoto != null) { var inputMediaUploadedPhoto75 = new TLInputMediaUploadedPhoto75(inputMediaUploadedPhoto, null); captionMedia = inputMediaUploadedPhoto75; media = inputMediaUploadedPhoto75; serverFile.Media = inputMediaUploadedPhoto75; StateService.SaveServerFilesAsync(results); } } if (captionMedia != null) { captionMedia.Caption = message.Message ?? TLString.Empty; } var ttlMedia = media as IInputTTLMedia; if (ttlMedia != null) { ttlMedia.TTLSeconds = ((TLMessageMediaPhoto70)message.Media).TTLSeconds; } message.InputMedia = media; UploadService.SendMediaInternal(message, MTProtoService, StateService, CacheService); } else { var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; UploadFileManager.UploadFile(fileId, message, bytes); } }); }
/// <summary> /// 获取塞券任务状态 /// </summary> /// <param name="batchcode"></param> /// <returns></returns> public ActionResult GetFileTaskStatus(string batchcode) { var result = new UploadFileManager().GetFileTaskStatus(batchcode, FileType.VipPaintPackage); return(Json(new { Status = !string.IsNullOrWhiteSpace(result), Data = result }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 上传附件,兼容非表单附件 /// </summary> /// <param name="file">文件</param> /// <returns></returns> public JsonResult UploadAttachment(IFormFileCollection file) { if (file == null || file.Count() == 0) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } SetRequest(_Request); Guid? moduleId = _Request.QueryEx("moduleId").ObjToGuidNull(); //模块Id,针对表单附件 Guid? id = _Request.QueryEx("id").ObjToGuidNull(); //记录Id,针对表单附件 bool isCreateSwf = _Request.QueryEx("isCreateSwf").ObjToBool(); //是否创建SWF文件 string attachType = _Request.QueryEx("attachType").ObjToStr(); //附件类型 string message = string.Empty; StringBuilder msg = new StringBuilder(); List <AttachFileInfo> fileMsg = new List <AttachFileInfo>(); foreach (var item in file) { try { string fileSize = FileOperateHelper.FileSize(item.Length); string fileType = Path.GetExtension(item.FileName); string fileName = item.FileName; string pathFlag = System.IO.Path.DirectorySeparatorChar.ToString(); int s = fileName.LastIndexOf(pathFlag); if (s >= 0) { fileName = fileName.Substring(s + 1); } //保存文件 string filePath = string.Empty; if (moduleId.HasValue) //表单附件 { filePath = UploadFileManager.SaveAs(item, "Attachment", "Temp"); } else { filePath = UploadFileManager.SaveAs(item, "Temp"); } filePath = filePath.StartsWith("~/") ? filePath : filePath.StartsWith("/") ? "~" + filePath : "~/" + filePath; //swf保存路径 string swfPath = string.Empty; //pdf保存路径 string pdfPath = string.Empty; if (isCreateSwf && !moduleId.HasValue) { //exe路径 string exePath = WebHelper.MapPath("~/bin/SWFTools/pdf2swf.exe"); //bin路径 string binPath = WebHelper.MapPath("~/bin/"); if (fileType.Equals(".doc") || fileType.Equals(".docx") || fileType.Equals(".xls") || fileType.Equals(".xlsx") || fileType.Equals(".ppt") || fileType.Equals(".pptx") || fileType.Equals(".pdf")) { //取pdf和swf路径 SystemOperate.GetSwfFilePath(out pdfPath, out swfPath); //参数 string[] obj = new string[] { fileType, WebHelper.MapPath(filePath), WebHelper.MapPath(pdfPath), WebHelper.MapPath(swfPath), exePath, binPath }; SystemOperate.CreateSwfFile(obj); } } fileMsg.Add(new AttachFileInfo() { AttachFile = filePath, PdfFile = pdfPath, SwfFile = swfPath, FileName = fileName, FileType = fileType, FileSize = fileSize, AttachType = attachType }); } catch (Exception ex) { msg.AppendLine(item.FileName + "上传失败:" + ex.Message); break; } } if (moduleId.HasValue && moduleId.Value != Guid.Empty && id.HasValue && id.Value != Guid.Empty) //查看页面,直接保存附件 { return(SaveFormAttach(moduleId.Value, id.Value, JsonHelper.Serialize(fileMsg), true)); } return(Json(new { Success = string.IsNullOrEmpty(msg.ToString()), Message = string.IsNullOrEmpty(msg.ToString()) ? "上传成功" : msg.ToString(), FileMsg = fileMsg.Count > 0 ? JsonHelper.Serialize(fileMsg) : string.Empty })); }