public async Task <HttpResponseMessage> PostFile() { HttpRequestMessage request = this.Request; if (!request.Content.IsMimeMultipartContent()) { return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, new HttpError("This needs to be in multipart format"))); } var provider = GetMultipartProvider(); var result = await Request.Content.ReadAsMultipartAsync(provider); var originalFileName = GetDeserializedFileName(result.FileData.First()); var uploadedFileInfo = new FileInfo(result.FileData.First().LocalFileName); var uploadModel = new UploadDataModel { projectName = result.FormData["projectName"], username = result.FormData["username"] }; var returnData = "ReturnTest"; return(this.Request.CreateResponse(HttpStatusCode.OK, new { returnData })); }
public async Task <HttpResponseMessage> PicturesAdd() { if (!Request.Content.IsMimeMultipartContent()) { this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType); } try { var provider = GetMultipartProvider(); var result = await Request.Content.ReadAsMultipartAsync(provider); List <Picture> assets = new List <Picture>(); foreach (MultipartFileData mfd in result.FileData) { // On upload, files are given a generic name like "BodyPart_26d6abe1-3ae1-416a-9429-b35f15e6e5d5" // so this is how you can get the original file name var originalFileName = GetDeserializedFileName(mfd); // uploadedFileInfo object will give you some additional stuff like file length, // creation time, directory name, a few filesystem methods etc.. var uploadedFileInfo = new FileInfo(mfd.LocalFileName); string mimeType = mfd.Headers.ContentType.MediaType; var asset = Picture.getPictureWithInfos(originalFileName, mimeType, uploadedFileInfo); assets.Add(asset); db.Pictures.Add(asset); // Through the request response you can return an object to the Angular controller // You will be able to access this in the .success callback through its data attribute // If you want to send something to the .error callback, use the HttpStatusCode.BadRequest instead } if (provider.FormData.AllKeys.Contains("uploadData")) { string val = Uri.UnescapeDataString(provider.FormData.GetValues("uploadData").FirstOrDefault() ?? String.Empty); UploadDataModel upload = Newtonsoft.Json.JsonConvert.DeserializeObject <UploadDataModel>(val); switch (upload.Model) { case "Dish": var item = await db.Dishes.FindAsync(upload.Id); if (item != null) { foreach (Picture m in assets) { item.Pictures.Add(m); } await db.SaveChangesAsync(); } break; } } await db.SaveChangesAsync(); return(this.Request.CreateResponse(HttpStatusCode.OK, assets)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public IActionResult UploadUserData() { var uploadDataModel = new UploadDataModel(); uploadDataModel.UploadDataTypes = _getUpLoadDataTypeList.Get().Select(x => new SelectListItem { Value = $"{x.Id}", Text = x.Name }); return(View(uploadDataModel)); }
/// <summary> /// Check processing /// </summary> /// <param name="inputObject">DataModel</param> /// <returns>ResultModel</returns> private void Check(UploadDataModel inputObject) { // Check valid if (DataCheckHelper.IsNull(inputObject.InputStream)) { throw new ExecuteException("E_MSG_00004", "Tập tin"); } if (!StorageFileCom.MapImageSize.ContainsKey(inputObject.FileGroup)) { throw new ExecuteException("E_MSG_00001", "Nhóm tập tin"); } }
/// <summary> /// Execute convert output. /// </summary> /// <param name="resultObject">DataModel</param> /// <returns>ResponseModel</returns> private UploadResponseModel Convert(UploadDataModel resultObject) { // Local variable declaration UploadResponseModel responseModel = null; // Variable initialize responseModel = new UploadResponseModel(); // Set value responseModel.AddMessage(MessageHelper.GetMessageInfo("I_MSG_00005")); // Return value return(responseModel); }
/// <summary> /// Execute convert input. /// </summary> /// <param name="request">RequestModel</param> /// <returns>DataModel</returns> private UploadDataModel Convert(UploadRequestModel request) { // Local variable declaration UploadDataModel inputObject = null; // Variable initialize inputObject = new UploadDataModel(); // Convert data input DataHelper.ConvertInput(request, inputObject); // Return value return(inputObject); }
/// <summary> /// Upload infomation /// </summary> /// <param name="inputObject">DataModel</param> /// <returns>DataModel</returns> private UploadDataModel UploadInfo(UploadDataModel inputObject) { // Local variable declaration UploadDataModel getResult = null; StorageFileCom storageFileCom = null; // Variable initialize getResult = new UploadDataModel(); storageFileCom = new StorageFileCom(); // Get data var fileId = inputObject.FileId; var maxFileNo = storageFileCom.GetMaxFileNo(fileId); // Set data var param = new StorageFile(); param.FileId = fileId; param.FileNo = maxFileNo + 1; param.FileName = DataHelper.GetUniqueKey() + ".jpg"; param.FileGroup = inputObject.FileGroup; param.SortKey = inputObject.SortKey; // Upload data // Upload Full size var path = string.Format("/pages/media/images/{0}/{1}/{2}", inputObject.FileGroup, "zoom", param.FileName); UploadHelper.UploadImage(inputObject.InputStream, path); // Upload Fix size var uploadList = StorageFileCom.MapImageSize[param.FileGroup]; foreach (var obj in uploadList) { path = string.Format("/pages/media/images/{0}/{1}/{2}", inputObject.FileGroup, obj.SizeName, param.FileName); UploadHelper.UploadImage(inputObject.InputStream, obj.Width, obj.Height, path); } // Insert data storageFileCom.Insert(param); // Submit data storageFileCom.SubmitChanges(); // Return value return(getResult); }
public async Task <IActionResult> UploadUserData(UploadDataModel uploadDataModel, IList <IFormFile> files) { uploadDataModel.UploadDataTypes = _getUpLoadDataTypeList.Get().Select(x => new SelectListItem { Value = $"{x.Id}", Text = x.Name }); uploadDataModel.UploadTypeId = uploadDataModel.UploadTypeId; var saveUploadModel = new SaveDataModel() { UploadTypeId = uploadDataModel.UploadTypeId, Tags = uploadDataModel.Tags }; foreach (var file in files) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var rootFilePath = _appSettings.Value.SharePath; // full path to file in temp location var filePath = Path.GetFullPath(rootFilePath); // checked file types if (fileName.EndsWith(".xlsx") || fileName.EndsWith(".csv")) { var dateTime = DateTime.Now; filePath = $"{filePath}\\{GetGUID()}_{fileName}"; await SaveFileToServerAsync(filePath); async Task SaveFileToServerAsync(string fileFullPath) { using (var stream = new FileStream(fileFullPath, FileMode.Create)) { await file.CopyToAsync(stream); } } } saveUploadModel.FilePath = filePath; saveUploadModel.ClientFileName = fileName; } var saveStatus = _saveUploadDataCommand.Upload(saveUploadModel); //update tags uploadDataModel.StatusCode = (saveStatus.IsUploaded) ? 1 : 2; uploadDataModel.StatusMessage = saveStatus.StatusMessage; uploadDataModel.Summary = $"{saveStatus.UploadedRows} rows uploaded out of {saveStatus.TotalRows}"; return(View(uploadDataModel)); }
public async Task <HttpResponseMessage> Upload() { if (!Request.Content.IsMimeMultipartContent()) { this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType); } var provider = GetMultipartProvider(); var result = await Request.Content.ReadAsMultipartAsync(provider); var originalFileName = GetDeserializedFileName(result.FileData.FirstOrDefault()); var uploadedFileInfo = new FileInfo(result.FileData.First().LocalFileName); UploadDataModel objUploadDataModel = new UploadDataModel(); UploadDataModel fileUploadObj = (UploadDataModel)GetFormData <UploadDataModel>(result); string FileNameWithPath = uploadedFileInfo.FullName; DataTable dt = new DataTable(); dt.Columns.Add("FirstName", typeof(string)); dt.Columns.Add("MiddleName", typeof(string)); dt.Columns.Add("LastName", typeof(string)); dt.Columns.Add("Address", typeof(string)); dt.Columns.Add("City", typeof(string)); dt.Columns.Add("StateName", typeof(string)); dt.Columns.Add("ZIP", typeof(string)); dt.Columns.Add("PrimaryPhone", typeof(string)); dt.Columns.Add("AlternatePhone", typeof(string)); dt.Columns.Add("Email", typeof(string)); dt.Columns.Add("SSN", typeof(string)); dt = ConvertExcelToDataTable(FileNameWithPath); System.Data.DataColumn newColumn = new System.Data.DataColumn("UserTypeId", typeof(int)); newColumn.DefaultValue = 1; dt.Columns.Add(newColumn); System.Data.DataColumn newColumn2 = new System.Data.DataColumn("CompanyId", typeof(int)); newColumn2.DefaultValue = GetCompanyId(int.Parse(fileUploadObj.testString1)).Rows[0][0].ToString(); dt.Columns.Add(newColumn2); return(this.Request.CreateResponse(HttpStatusCode.OK, new { dt })); }
public async Task <JsonResult> ConfirmUpload(UploadDataModel model) { if (ModelState.IsValid & model != null) { var upload = new UploadEntity(User.Identity.GetUserId(), model.BankId, model.BranchId, 0); bool result = false; try { result = await UploadManager.CreateAsync(upload); } catch (Exception ex) { throw new Exception(ex.Message); } if (result) { try { foreach (var data in model.PData) { var uploaddata = new UploadDataEntity(upload.Id, data.Narration, data.Amount, data.AccountNumber, data.Debit1Credit0, data.PostingCode, data.TranID, data.TranDate, 0); UploadDataManager.Create(uploaddata); } } catch (Exception ex) { //TODO: implement log UploadDataManager.Delete(upload.Id); UploadManager.Delete(upload); throw new Exception("Upload failed"); } var branchDetail = await Helper.GetBranchNameAndCode(upload.BranchId); new EmailSender().SendToBranchOperator(branchDetail["BranchCode"]); return(Json(new { code = "00", message = "Successful" }, JsonRequestBehavior.AllowGet)); } else { throw new Exception("Upload creation failed"); } } throw new Exception("Invalid Data Submitted"); }
/// <summary> /// Execute processing. /// </summary> /// <param name="request">RequestModel</param> /// <returns>ResponseModel</returns> private UploadResponseModel Execute(UploadRequestModel request) { // Local variable declaration UploadResponseModel responseModel = null; UploadDataModel inputObject = null; UploadDataModel resultObject = null; // Variable initialize responseModel = new UploadResponseModel(); // Execute convert input. inputObject = Convert(request); // Check infomation Check(inputObject); // Upload infomation resultObject = UploadInfo(inputObject); // Execute convert ouput. responseModel = Convert(resultObject); return(responseModel); }
public ActionResult GetUploadedPdfFiles(FileUploadModel files) { List <ArticleModel> aArticleModelList = new List <ArticleModel>(); List <UploadDataModel> aUploadDataModelList = new List <UploadDataModel>(); foreach (var item in files.File) { IndividualFileRead aIndividualFileRead = new IndividualFileRead(); List <DataModel> listOfAllLines = new List <DataModel>(); listOfAllLines = aIndividualFileRead.MethodToIndividualFileRead(item); //got all data in lines ExtractionOfCharacteristics aExtractionOfCharacteristics = new ExtractionOfCharacteristics(); ArticleModel aArticleModel = new ArticleModel(); aArticleModel = aExtractionOfCharacteristics.Method(listOfAllLines);//got the data in form of ArticleModel(title,list) aArticleModelList.Add(aArticleModel); //25/04/2018 //database portion UploadDataModel aUploadDataModel = new UploadDataModel(); aUploadDataModel.artitleTitle = aArticleModel.articleTitle; // portion starts for uploading in the database ArrayListUpload aArrayListUpload = new ArrayListUpload(); int titleId = aArrayListUpload.TitleUploadMethod(aArticleModel); if (titleId == (-1)) { //isAlreadyExists aUploadDataModel.uploadProcessMessage = "Article data is already existed";//"Title is already exists"; } else if (titleId == (-2)) { //notSavedSuccessfully aUploadDataModel.uploadProcessMessage = "Not saved successfully"; } else if (titleId == 0) { //noExecutionHappened aUploadDataModel.uploadProcessMessage = "no execution happened, try again"; } else { //saveRestDataWithID int articleSavedresult = aArrayListUpload.ArticleDataUploadMethod(titleId, aArticleModel.articleSeparateParagraphs); if (articleSavedresult == -3 || articleSavedresult == 0) { aUploadDataModel.uploadProcessMessage = "Article data not saved successfully"; } else { aUploadDataModel.uploadProcessMessage = "Article data saved successfully"; } } aUploadDataModelList.Add(aUploadDataModel); } TempData["list"] = aUploadDataModelList; return(RedirectToAction("GetAllUploadedTitlesResults", "Home" /*new { ListOfUploadedTitles=aUploadDataModelList }*/)); }
/// <summary> /// 立即提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSubmit_Click(object sender, EventArgs e) { string phone = txtPhone.Text; string date = txtDate.Text; if (string.IsNullOrEmpty(phone)) { MessageBox.Show(TextKit.failMsg, "操作提示"); return; } if (!ValidateKit.isMobile(phone)) { MessageBox.Show(TextKit.failMobileMsg, "操作提示"); return; } DataGridViewRow row = new DataGridViewRow(); //排序 DataGridViewTextBoxCell sort = new DataGridViewTextBoxCell(); sort.Value = Convert.ToInt32(dataGridView.Rows.Count + 1); row.Cells.Add(sort); //手机号 DataGridViewTextBoxCell phoneCell = new DataGridViewTextBoxCell(); phoneCell.Value = phone; row.Cells.Add(phoneCell); DataGridViewTextBoxCell starttime = new DataGridViewTextBoxCell(); starttime.Value = date; row.Cells.Add(starttime); DataGridViewTextBoxCell transcodeCell = new DataGridViewTextBoxCell(); transcodeCell.Value = "等待转码"; row.Cells.Add(transcodeCell); DataGridViewTextBoxCell upCell = new DataGridViewTextBoxCell(); upCell.Value = "等待资源"; row.Cells.Add(upCell); DataGridViewTextBoxCell inPathCell = new DataGridViewTextBoxCell(); inPathCell.Value = this.pbInPath; row.Cells.Add(inPathCell); DataGridViewTextBoxCell outPathCell = new DataGridViewTextBoxCell(); outPathCell.Value = this.pbOutPath; row.Cells.Add(outPathCell); dataGridView.Rows.Add(row); DataModel data = new DataModel(); data.phone = phone; data.starttime = date; data.op = phone + " " + pbInPath + " " + pbOutPath;; data.sort = dataGridView.Rows.Count - 1; //获取个人摆拍 if (!string.IsNullOrEmpty(this.pbPhotoPath)) { data.photo = this.pbPhotoPath; //copy个性摆拍 System.IO.File.Copy(data.photo, System.IO.Directory.GetCurrentDirectory() + @"\ffmpeg\output\" + data.phone + ".jpg"); } UploadDataModel m = new UploadDataModel(); m.phone = data.phone; m.starttime = data.starttime; m.mac = MacKit.GetMacString(); FileKit.createFile(JsonConvert.SerializeObject(m), System.IO.Directory.GetCurrentDirectory() + @"\ffmpeg\output\" + data.phone + ".json"); txtPhone.Text = ""; txtDate.Text = ""; pbIn.Image = global::VideoApplication.Properties.Resources._in; pbOut.Image = global::VideoApplication.Properties.Resources._out; pbPhoto.Image = global::VideoApplication.Properties.Resources.image; this.pbInPath = ""; this.pbOutPath = ""; this.pbPhotoPath = ""; wirteGridData(); QueueKit.q.Enqueue(data); }
private void MainForm_Load(object sender, EventArgs e) { List <DataModel> data = JsonConvert.DeserializeObject <List <DataModel> >(FileKit.getData(FileKit.dataPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".json")); if (data != null) { foreach (DataModel m in data) { DataGridViewRow row = new DataGridViewRow(); //排序 DataGridViewTextBoxCell sort = new DataGridViewTextBoxCell(); sort.Value = m.sort; row.Cells.Add(sort); //手机号 DataGridViewTextBoxCell phoneCell = new DataGridViewTextBoxCell(); phoneCell.Value = m.phone; row.Cells.Add(phoneCell); DataGridViewTextBoxCell starttime = new DataGridViewTextBoxCell(); starttime.Value = m.starttime; row.Cells.Add(starttime); DataGridViewTextBoxCell transcodeCell = new DataGridViewTextBoxCell(); transcodeCell.Value = m.transStatus; row.Cells.Add(transcodeCell); DataGridViewTextBoxCell ftpCell = new DataGridViewTextBoxCell(); ftpCell.Value = m.ftpStatus; row.Cells.Add(ftpCell); DataGridViewTextBoxCell inPathCell = new DataGridViewTextBoxCell(); inPathCell.Value = m.inpath; row.Cells.Add(inPathCell); DataGridViewTextBoxCell outPathCell = new DataGridViewTextBoxCell(); outPathCell.Value = m.outpath; row.Cells.Add(outPathCell); dataGridView.Rows.Add(row); DataModel dataQueueModel = new DataModel(); dataQueueModel.phone = m.phone; dataQueueModel.starttime = m.starttime; dataQueueModel.op = m.phone + " " + m.inpath + " " + m.outpath;; dataQueueModel.sort = m.sort - 1; //未转码成功,重新转码 if (m.transStatus != TextKit.transStatusSuccess) { //获取个人摆拍 if (!string.IsNullOrEmpty(m.photo)) { //copy个性摆拍 System.IO.File.Copy(m.photo, System.IO.Directory.GetCurrentDirectory() + @"\ffmpeg\output\" + m.phone + ".jpg"); } transcodeCell.Value = "等待转码"; ftpCell.Value = "等待资源"; QueueKit.q.Enqueue(dataQueueModel); } else { //未上传成功,重新上传 if (m.ftpStatus != TextKit.ftpStatusSuccess) { UploadDataModel uploadModel = new UploadDataModel(); uploadModel.phone = m.phone; uploadModel.starttime = m.starttime; uploadModel.mac = MacKit.GetMacString(); FileKit.createFile(JsonConvert.SerializeObject(m), System.IO.Directory.GetCurrentDirectory() + @"\ffmpeg\output\" + m.phone + ".json"); ftpCell.Value = "等待资源"; QueueKit.qftp.Enqueue(dataQueueModel); } } } } monitorQueue(); }