Exemplo n.º 1
0
        public ActionResult SaveFileUpload(IEnumerable <HttpPostedFileBase> files, string formatString)
        {
            var model = new UploadModel();

            if (files != null)
            {
                foreach (var file in files)
                {
                    var _fileName = file.FileName;
                    if (!string.IsNullOrEmpty(formatString))
                    {
                        string fileExt  = Path.GetExtension(_fileName);
                        string filename = Path.GetFileNameWithoutExtension(_fileName);
                        //string fileSuffix = DateTime.Now.ToString("ddmmyyyyHHmmss");
                        _fileName = filename + formatString + fileExt;
                    }
                    var fileName = Common.TemplateURL + "\\" + _fileName;
                    fileName = fileName.Replace("/", "");
                    //var physicalPath = Path.Combine(Server.MapPath("~/"+Common.TemplateURL), fileName);
                    var physicalPath = Common.GetPath(fileName);
                    file.SaveAs(physicalPath);

                    string fileUrl = _hrm_Main_Web + fileName;
                    fileUrl        = fileUrl.Replace("\\", "/");
                    model.FileName = _fileName; //file.FileName;
                    model.FileUrl  = fileUrl;
                    model.Status   = true;
                }
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult Upload(UploadModel model)
        {
            if (ModelState.IsValid)
            {
                ShopConfigInfo shopConfigInfo = BSPConfig.ShopConfig;

                shopConfigInfo.UploadImgType           = model.UploadImgType;
                shopConfigInfo.UploadImgSize           = model.UploadImgSize * 1000;
                shopConfigInfo.WatermarkType           = model.WatermarkType;
                shopConfigInfo.WatermarkQuality        = model.WatermarkQuality;
                shopConfigInfo.WatermarkPosition       = model.WatermarkPosition;
                shopConfigInfo.WatermarkImg            = model.WatermarkImg == null ? "" : model.WatermarkImg;
                shopConfigInfo.WatermarkImgOpacity     = model.WatermarkImgOpacity;
                shopConfigInfo.WatermarkText           = model.WatermarkText == null ? "" : model.WatermarkText;
                shopConfigInfo.WatermarkTextFont       = model.WatermarkTextFont;
                shopConfigInfo.WatermarkTextSize       = model.WatermarkTextSize;
                shopConfigInfo.BrandThumbSize          = model.BrandThumbSize;
                shopConfigInfo.ProductShowThumbSize    = model.ProductShowThumbSize;
                shopConfigInfo.UserAvatarThumbSize     = model.UserAvatarThumbSize;
                shopConfigInfo.UserRankAvatarThumbSize = model.UserRankAvatarThumbSize;

                BSPConfig.SaveShopConfig(shopConfigInfo);
                Emails.ResetShop();
                SMSes.ResetShop();
                AddAdminOperateLog("修改上传设置");
                return(PromptView(Url.Action("upload"), "修改上传设置成功"));
            }

            LoadFont();
            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <UploadModel> UploadFileAsync(IFormFile file, string contentType)
        {
            UploadModel uploadModel = new UploadModel();

            if (file != null)
            {
                if (file.ContentType != contentType)
                {
                    uploadModel.ErrorMessage = "This type of file is not supported";
                    uploadModel.UploadState  = UploadState.Error;
                    return(uploadModel);
                }
                else
                {
                    var newName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    var path    = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/profile/" + newName);
                    var stream  = new FileStream(path, FileMode.Create);
                    await file.CopyToAsync(stream);

                    uploadModel.NewName     = newName;
                    uploadModel.UploadState = UploadState.Succes;
                    return(uploadModel);
                }
            }

            uploadModel.ErrorMessage = "Didn't update any file";
            uploadModel.UploadState  = UploadState.NotExist;
            return(uploadModel);
        }
        public FileUploadJsonResult AjaxUpload(HttpPostedFileBase file, UploadModel model)
        {
            if (file != null && !string.IsNullOrEmpty(file.FileName))
            {
                // here you can save your file to the database...
                var doc = new DocumentModel
                {
                    Id           = Docs.Count + 1,
                    DocumentName = file.FileName,
                    RecievedDate = DateTime.Now,
                    UploadDate   = DateTime.Now
                };
                Docs.Add(doc);
            }

            if (file == null)
            {
                return new FileUploadJsonResult {
                           Data = new { message = "FileUploadJsonResultMessage" }
                }
            }
            ;

            return(new FileUploadJsonResult {
                Data = new { message = System.IO.Path.GetFileName(file.FileName) + "FileUploadJsonResultMessageSuccess" }
            });
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Upload(UploadModel model)
        {
            byte[] buffer = new byte[BUF_SIZE];

            foreach (var s in model.Files)
            {
                using (var stream = s.OpenReadStream())
                    while (await stream.ReadAsync(buffer, 0, buffer.Length) > 0)
                    {
                        ;
                    }
            }

            return(Ok(new {
                model.Name,
                model.Description,
                files = model.Files.Select(x => new {
                    x.Name,
                    x.FileName,
                    x.ContentDisposition,
                    x.ContentType,
                    x.Length
                })
            }));
        }
Exemplo n.º 6
0
        public IActionResult Upload(IFormCollection form)
        {
            var stl        = form.Files[0];
            var subpath    = "/uploads/" + Guid.NewGuid().ToString() + ".stl";
            var filePath   = Startup._env.WebRootPath + subpath;
            var fileStream = FILE.Create(filePath);

            var stream = stl.OpenReadStream();

            stream.Seek(0, System.IO.SeekOrigin.Begin);
            stream.CopyTo(fileStream);
            stream.Close();
            fileStream.Close();

            var model = new UploadModel()
            {
                dt       = DateTime.Now,
                subpath  = subpath,
                filename = stl.FileName,
            };

            model.FillStlInfo(filePath);

            var id = db.Uploads.Insert(model);

            return(Json(new { id = id.AsString }));
        }
Exemplo n.º 7
0
        public ActionResult Upload(HttpPostedFileBase file, string tooltip)
        {
            string PHYSICAL_PATH = WebConfigurationManager.AppSettings["physicalPathContent"];

            try
            {
                string      imagePath = PHYSICAL_PATH + "Images\\nav";
                UploadModel model     = new UploadModel();
                String      path1     = "";
                string      path      = "";
                string      pathUI    = "";
                if (file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    path   = Path.Combine(Server.MapPath("~/Content/Images/nav"), fileName);
                    pathUI = Path.Combine(imagePath, fileName);
                    path1  = "~/Content/Images/nav/" + fileName;
                    file.SaveAs(path);
                    file.SaveAs(pathUI);
                }
                ViewBag.Message = "Upload successful";
                model.ImageUrl  = path1;
                model.tooltip   = tooltip;
                return(PartialView("Example", model));
            }
            catch
            {
                ViewBag.Message = "Upload failed";
                return(PartialView("Example"));
            }
        }
Exemplo n.º 8
0
        public ActionResult Example()
        {
            UploadModel model = new UploadModel();

            model.ImageUrl = "";
            return(PartialView("Example", model));
        }
Exemplo n.º 9
0
        public async Task <Boolean> UploadFiles(UploadModel model)
        {
            string uri;
            int    count = 0;

            foreach (var file in model.Files)
            {
                count++;
                uri = $"FTP://{model.ServerIp}/{model.DirectoryPath}/{file.FileName}";
                var ftp = (FtpWebRequest)WebRequest.Create(uri);                         //建立FTP連線
                ftp.Credentials = new NetworkCredential(model.UserName, model.Passwrod); //帳密驗證
                ftp.KeepAlive   = count == model.Files.Count ? false : true;             //關閉/保持 連線
                ftp.Timeout     = 2000;                                                  //等待時間
                ftp.UseBinary   = true;                                                  //傳輸資料型別 二進位/文字
                ftp.UsePassive  = false;                                                 //通訊埠接聽並等待連接
                ftp.Method      = WebRequestMethods.Ftp.UploadFile;                      //上傳檔案
                ftp.Proxy       = null;

                try
                {
                    using (var request = ftp.GetRequestStream())
                    {
                        await request.WriteAsync(file.FileContents, 0, file.FileContents.Length);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(true);;
        }
Exemplo n.º 10
0
        public ActionResult Upload()
        {
            ShopConfigInfo shopConfigInfo = BSPConfig.ShopConfig;

            UploadModel model = new UploadModel();

            model.UploadServer            = shopConfigInfo.UploadServer;
            model.UploadImgType           = shopConfigInfo.UploadImgType;
            model.UploadImgSize           = shopConfigInfo.UploadImgSize / 1000;
            model.WatermarkType           = shopConfigInfo.WatermarkType;
            model.WatermarkQuality        = shopConfigInfo.WatermarkQuality;
            model.WatermarkPosition       = shopConfigInfo.WatermarkPosition;
            model.WatermarkImg            = shopConfigInfo.WatermarkImg;
            model.WatermarkImgOpacity     = shopConfigInfo.WatermarkImgOpacity;
            model.WatermarkText           = shopConfigInfo.WatermarkText;
            model.WatermarkTextFont       = shopConfigInfo.WatermarkTextFont;
            model.WatermarkTextSize       = shopConfigInfo.WatermarkTextSize;
            model.BrandThumbSize          = shopConfigInfo.BrandThumbSize;
            model.ProductShowThumbSize    = shopConfigInfo.ProductShowThumbSize;
            model.UserAvatarThumbSize     = shopConfigInfo.UserAvatarThumbSize;
            model.UserRankAvatarThumbSize = shopConfigInfo.UserRankAvatarThumbSize;

            LoadFont();
            return(View(model));
        }
Exemplo n.º 11
0
        public ActionResult Upload(UploadModel model)
        {
            if (ModelState.IsValid)
            {
                UploadConfigInfo uploadConfigInfo = BMAConfig.UploadConfig;

                uploadConfigInfo.UploadImgType            = model.UploadImgType;
                uploadConfigInfo.UploadImgSize            = model.UploadImgSize * 1000;
                uploadConfigInfo.WatermarkType            = model.WatermarkType;
                uploadConfigInfo.WatermarkQuality         = model.WatermarkQuality;
                uploadConfigInfo.WatermarkPosition        = model.WatermarkPosition;
                uploadConfigInfo.WatermarkImg             = model.WatermarkImg == null ? "" : model.WatermarkImg;
                uploadConfigInfo.WatermarkImgOpacity      = model.WatermarkImgOpacity;
                uploadConfigInfo.WatermarkText            = model.WatermarkText == null ? "" : model.WatermarkText;
                uploadConfigInfo.WatermarkTextFont        = model.WatermarkTextFont;
                uploadConfigInfo.WatermarkTextSize        = model.WatermarkTextSize;
                uploadConfigInfo.BrandThumbSize           = model.BrandThumbSize;
                uploadConfigInfo.ProductShowThumbSize     = model.ProductShowThumbSize;
                uploadConfigInfo.UserAvatarThumbSize      = model.UserAvatarThumbSize;
                uploadConfigInfo.UserRankAvatarThumbSize  = model.UserRankAvatarThumbSize;
                uploadConfigInfo.StoreRankAvatarThumbSize = model.StoreRankAvatarThumbSize;
                uploadConfigInfo.StoreLogoThumbSize       = model.StoreLogoThumbSize;

                BMAConfig.SaveUploadConfig(uploadConfigInfo);
                AddMallAdminLog("修改上传设置");
                return(PromptView(Url.Action("upload"), "修改上传设置成功"));
            }

            LoadFont();
            return(View(model));
        }
Exemplo n.º 12
0
        public ActionResult Upload()
        {
            UploadConfigInfo uploadConfigInfo = BMAConfig.UploadConfig;

            UploadModel model = new UploadModel();

            model.UploadImgType            = uploadConfigInfo.UploadImgType;
            model.UploadImgSize            = uploadConfigInfo.UploadImgSize / 1000;
            model.WatermarkType            = uploadConfigInfo.WatermarkType;
            model.WatermarkQuality         = uploadConfigInfo.WatermarkQuality;
            model.WatermarkPosition        = uploadConfigInfo.WatermarkPosition;
            model.WatermarkImg             = uploadConfigInfo.WatermarkImg;
            model.WatermarkImgOpacity      = uploadConfigInfo.WatermarkImgOpacity;
            model.WatermarkText            = uploadConfigInfo.WatermarkText;
            model.WatermarkTextFont        = uploadConfigInfo.WatermarkTextFont;
            model.WatermarkTextSize        = uploadConfigInfo.WatermarkTextSize;
            model.BrandThumbSize           = uploadConfigInfo.BrandThumbSize;
            model.ProductShowThumbSize     = uploadConfigInfo.ProductShowThumbSize;
            model.UserAvatarThumbSize      = uploadConfigInfo.UserAvatarThumbSize;
            model.UserRankAvatarThumbSize  = uploadConfigInfo.UserRankAvatarThumbSize;
            model.StoreRankAvatarThumbSize = uploadConfigInfo.StoreRankAvatarThumbSize;
            model.StoreLogoThumbSize       = uploadConfigInfo.StoreLogoThumbSize;

            LoadFont();
            return(View(model));
        }
Exemplo n.º 13
0
        public async Task <UploadModel> Post()
        {
            var         uploadService = InjectorManager.GetInstance <UploadArquivoService>();
            UploadModel model         = null;

            var provider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(provider).
            ContinueWith(o =>
            {
                var fileContent = provider.Contents.SingleOrDefault();

                if (fileContent != null)
                {
                    var fileName = fileContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);
                    var type     = fileContent.Headers.ContentType.MediaType;
                    var blob     = fileContent.ReadAsByteArrayAsync().Result;

                    var stream = fileContent.ReadAsStreamAsync().Result;
                    var upload = ImageService.ResizeAndCompress(stream);

                    model = uploadService.SalvarArquivo(upload);
                }
            });

            return(model);
        }
        public async Task <IActionResult> UploadPost(UploadModel uploadModel)
        {
            if (uploadModel.File == null ||
                !UploadHelper.IsSingleContentType(uploadModel.File) ||
                !UploadHelper.HasAValidExtention(uploadModel.File, _extensionsPermitted) ||
                !UploadHelper.IsInLengthLimits(uploadModel.File, _fileMaxLengthLimit))
            {
                return(RedirectToAction("UploadPhotos", new UploadModel {
                    Message = _localizer["File not suported"]
                }));
            }

            var response = await MyUploadManager.UploadNewPhoto(uploadModel.File, _userId);

            if (response.IsSuccess)
            {
                return(RedirectToAction("UploadPhotos", new UploadModel {
                    Message = _localizer["File uploaded"]
                }));
            }
            else
            {
                return(RedirectToAction("UploadPhotos", new UploadModel {
                    Message = _localizer["Internal error :("]
                }));
            }
        }
Exemplo n.º 15
0
        public async Task <UploadModel> UploadFormFileAsync(IFormFile file, string contentType, string imageNameHeader = "image")
        {
            UploadModel uploadModel = new UploadModel();

            if (file != null)
            {
                if (file.ContentType == contentType)
                {
                    var imageName = $"{imageNameHeader}_" + Guid.NewGuid() + Path.GetExtension(file.FileName);
                    var path      = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/" + imageName);
                    using var fileStream = new FileStream(path, FileMode.Create);
                    await file.CopyToAsync(fileStream);

                    uploadModel.ImageName   = imageName;
                    uploadModel.UploadState = UploadState.Success;
                    return(uploadModel);
                }
                else
                {
                    uploadModel.ErrorMessage = "Invalid content type";
                    uploadModel.UploadState  = UploadState.Error;
                }
            }
            uploadModel.ErrorMessage = "File is null";
            uploadModel.UploadState  = UploadState.NotExists;
            return(uploadModel);
        }
Exemplo n.º 16
0
        public ActionResult Index()
        {
            var model = new UploadModel();

            model.Id = 0;
            return(View(model));
        }
Exemplo n.º 17
0
        public ActionResult Upload()
        {
            SiteConfigInfo siteConfigInfo = BSConfig.SiteConfig;

            UploadModel model = new UploadModel();

            model.UploadImgType = siteConfigInfo.UploadImgType;
            model.UploadImgSize = siteConfigInfo.UploadImgSize / 1000;
            model.UploadAttType = siteConfigInfo.UploadAttType;
            model.UploadAttSize = siteConfigInfo.UploadAttSize / 1000;
            model.WatermarkType = siteConfigInfo.WatermarkType;

            model.WatermarkQuality        = siteConfigInfo.WatermarkQuality;
            model.WatermarkPosition       = siteConfigInfo.WatermarkPosition;
            model.WatermarkImg            = siteConfigInfo.WatermarkImg;
            model.WatermarkImgOpacity     = siteConfigInfo.WatermarkImgOpacity;
            model.WatermarkText           = siteConfigInfo.WatermarkText;
            model.WatermarkTextFont       = siteConfigInfo.WatermarkTextFont;
            model.WatermarkTextSize       = siteConfigInfo.WatermarkTextSize;
            model.ArticleImgThumbSize     = siteConfigInfo.ArticleImgThumbSize;
            model.FriendLinkThumbSize     = siteConfigInfo.FriendLinkThumbSize;
            model.ArticleClassThumbSize   = siteConfigInfo.ArticleClassThumbSize;
            model.SpecialImgThumbSize     = siteConfigInfo.SpecialImgThumbSize;
            model.UserAvatarThumbSize     = siteConfigInfo.UserAvatarThumbSize;
            model.UserRankAvatarThumbSize = siteConfigInfo.UserRankAvatarThumbSize;

            LoadFont();
            return(View(model));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Updates an existing row in the database.
        /// </summary>
        private SaveResult UpdateImageUpload(Upload upload, UploadModel model)
        {
            if (model.Upload != null)
            {
                try
                {
                    string physicalLocation = StringHelpers.MapToServer(upload.PhysicalLocation);

                    if (File.Exists(physicalLocation))
                    {
                        File.Delete(physicalLocation);
                    }

                    model.Upload.SaveAs(physicalLocation);
                }
                catch// ( IOException ioException )
                {
                    // Log exception

                    return(SaveResult.WriteFailure);
                }
            }

            upload.UpdateTimeStamp();
            upload.Title       = model.Title;
            upload.Description = model.Description;

            base.Database.SaveChanges();

            return(SaveResult.Success);
        }
Exemplo n.º 19
0
        public ActionResult Upload(UploadModel model)
        {
            if (ModelState.IsValid)
            {
                SiteConfigInfo siteConfigInfo = BSConfig.SiteConfig;

                siteConfigInfo.UploadImgType           = model.UploadImgType;
                siteConfigInfo.UploadImgSize           = model.UploadImgSize * 1000;
                siteConfigInfo.UploadAttType           = model.UploadAttType;
                siteConfigInfo.UploadAttSize           = model.UploadAttSize * 1000;
                siteConfigInfo.WatermarkType           = model.WatermarkType;
                siteConfigInfo.WatermarkQuality        = model.WatermarkQuality;
                siteConfigInfo.WatermarkPosition       = model.WatermarkPosition;
                siteConfigInfo.WatermarkImg            = model.WatermarkImg == null ? "" : model.WatermarkImg;
                siteConfigInfo.WatermarkImgOpacity     = model.WatermarkImgOpacity;
                siteConfigInfo.WatermarkText           = model.WatermarkText == null ? "" : model.WatermarkText;
                siteConfigInfo.WatermarkTextFont       = model.WatermarkTextFont;
                siteConfigInfo.WatermarkTextSize       = model.WatermarkTextSize;
                siteConfigInfo.ArticleImgThumbSize     = model.ArticleImgThumbSize;
                siteConfigInfo.FriendLinkThumbSize     = model.FriendLinkThumbSize;
                siteConfigInfo.ArticleClassThumbSize   = model.ArticleClassThumbSize;
                siteConfigInfo.SpecialImgThumbSize     = model.SpecialImgThumbSize;
                siteConfigInfo.UserAvatarThumbSize     = model.UserAvatarThumbSize;
                siteConfigInfo.UserRankAvatarThumbSize = model.UserRankAvatarThumbSize;

                BSConfig.SaveSiteConfig(siteConfigInfo);
                //Emails.ResetShop();
                //SMSes.ResetShop();
                AddAdminOperateLog("修改上传设置");
                return(PromptView(Url.Action("upload"), "修改上传设置成功"));
            }

            LoadFont();
            return(View(model));
        }
Exemplo n.º 20
0
        public ActionResult UploadImage(int?uid)
        {
            UploadModel mode = new UploadModel();

            mode.PostUrl = Url.Action("UploadImage");
            return(View(mode));
        }
Exemplo n.º 21
0
        public ActionResult FileUpload2()
        {
            try
            {
                UploadModel model  = new UploadModel();
                var         result = new { Flag = false, Message = "上传文件失败。" };
                if (this.Request.Files.Count > 0)
                {
                    var file = this.Request.Files[0];

                    if (file.ContentLength > 1024 * 1024 * 2)
                    {
                        model.ReturnFlag = false;
                        model.Message    = "文件不能大于2M!";
                    }
                    else
                    {
                        model = ChatHelper.UploadFile(file, UNCConfig.GetCfg());
                    }
                }
                else
                {
                    model.ReturnFlag = false;
                    model.Message    = "找不到可以上传的文件!";
                }
                string jsonData = JsonConvert.SerializeObject(model);
                ViewData["r"] = jsonData;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(PartialView());
        }
        public string uploadEpreuve(UploadModel epreuve)
        {
            HttpPostedFileBase file     = epreuve.file;
            string             matiere  = epreuve.matiere;
            string             annee    = epreuve.annee;
            string             response = "1";

            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Epreuves/"), file.FileName);
                    file.SaveAs(path);
                    GestionConcourDbContext db = new GestionConcourDbContext();
                    Epreuves epr = new Epreuves();
                    epr.NomFichier = file.FileName;
                    epr.Matiere    = matiere;
                    epr.Annee      = annee;
                    db.Epreuves.Add(epr);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    response = ex.Message;
                }
            }
            else
            {
                response = "0";
            }
            return(response);
        }
        public override Task ExecutePostProcessingAsync()
        {
            foreach (var fileData in FileData)
            {
                var fileName = Path.GetFileName(fileData.Headers.ContentDisposition.FileName.Trim('"'));

                var blobContainer = Helper.GetBlobContainer();
                var blob          = blobContainer.GetBlockBlobReference(fileName);

                blob.Properties.ContentType = fileData.Headers.ContentType.MediaType;

                using (var fs = File.OpenRead(fileData.LocalFileName))
                {
                    blob.UploadFromStream(fs);
                }

                // Delete local file from disk
                File.Delete(fileData.LocalFileName);


                // Create blob upload model with properties from blob info
                var blobUpload = new UploadModel
                {
                    FileName        = blob.Name,
                    FileUrl         = blob.Uri.AbsoluteUri,
                    FileSizeInBytes = blob.Properties.Length
                };

                // Add uploaded blob to the list
                Uploads.Add(blobUpload);
            }

            return(base.ExecutePostProcessingAsync());
        }
Exemplo n.º 24
0
        public static int CreateUpload(UploadModel data)
        {
            string sql = @"insert into dbo.AudioFiles (Title, Client, Description, AudioFile, SenderID)
                            values (@Title, @Client, @Description, @AudioFile, @SenderID)";

            return(SQLDataAccess.SaveData(sql, data));
        }
Exemplo n.º 25
0
        public ActionResult Countries()
        {
            var model = new UploadModel();

            model.Id = 0;
            return(View(model));
        }
Exemplo n.º 26
0
        public async Task <UploadModel> UploadFile(IFormFile file, string contentType)
        {
            UploadModel uploadModel = new UploadModel();

            if (file != null)
            {
                if (file.ContentType != contentType)
                {
                    uploadModel.ErrorMessage = "Uygunsuz dosya türü";
                    uploadModel.UploadState  = Enums.UploadState.Error;
                    return(uploadModel);
                }
                else
                {
                    var imageName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    var path      = Directory.GetCurrentDirectory() + "/wwwroot/img/" + imageName;
                    var stream    = new FileStream(path, FileMode.Create);//Path and FileMode
                    await file.CopyToAsync(stream);

                    uploadModel.UploadState = Enums.UploadState.Success;
                    uploadModel.NewName     = imageName;
                    return(uploadModel);
                }
            }
            uploadModel.UploadState  = Enums.UploadState.NotExist;
            uploadModel.ErrorMessage = "Dosya yok";
            return(uploadModel);
        }
Exemplo n.º 27
0
        public UploadModel ToUploadModel(Upload upload)
        {
            UploadModel model = upload.Map <UploadModel>();

            model.Result = _voteService.GetResult(model.Id);
            return(model);
        }
Exemplo n.º 28
0
        public async Task <UploadModel> UploadFileAsync(IFormFile file, string contentType)
        {
            UploadModel uploadModel = new UploadModel();

            if (file != null)
            {
                if (file.ContentType != contentType)
                {
                    uploadModel.ErrorMessage = "Uygunsuz Dosya Türü";
                    uploadModel.UploadState  = UploadState.Error;
                    return(uploadModel);
                }
                else
                {
                    var newName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    var path    = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/" + newName);
                    var stream  = new FileStream(path, FileMode.Create);
                    await file.CopyToAsync(stream);

                    uploadModel.Newname     = newName;
                    uploadModel.UploadState = UploadState.Success;
                    return(uploadModel);
                }
            }
            uploadModel.ErrorMessage = "Dosya Bulunamadı";
            uploadModel.UploadState  = UploadState.NotExist;
            return(uploadModel);
        }
Exemplo n.º 29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IActionResult Index(UploadModel model)
        {
            var member = _workContext.CurrentMember;

            if (member == null)
            {
                throw new AlertException("未登录");
            }

            var guid      = Guid.NewGuid().ToString("N");
            var extension = "png";

            if (model.File.ContentType.Contains("jpeg") || model.File.ContentType.Contains("jpg"))
            {
                extension = "jpg";
            }
            else if (model.File.ContentType.Equals("video/mp4", StringComparison.OrdinalIgnoreCase))
            {
                extension = "mp4";
            }

            var file     = $"/upload/{guid}.{extension}";
            var filePath = Path.Combine(_environment.ContentRootPath, "wwwroot/upload");

            filePath = Path.Combine(filePath, $"{guid}.{extension}");
            using (var stream = new FileStream(filePath, FileMode.CreateNew))
            {
                model.File.CopyTo(stream);
            }

            return(RespJson(new { FullPath = file.GetFullPath(), RelativePath = file }));
        }
Exemplo n.º 30
0
        public void Upload()
        {
            var function = new FunctionUploadPhotos();
            var context  = new TestLambdaContext();

            byte[] imageArray = System.IO.File.ReadAllBytes(@"C:\Users\edwin.cavina\Desktop\edwin.jpg");
            string base64     = Convert.ToBase64String(imageArray);

            var request = new UploadModel
            {
                Id        = "OgbZCmsBfKkxXf3E1J6h",
                ImgBase64 = base64
            };
            var apiGateway = new APIGatewayProxyRequest
            {
                HttpMethod = "POST",
                Path       = "upload-photos",
                Body       = JsonConvert.SerializeObject(request),
                Headers    = new Dictionary <string, string>()
                {
                    { "Content-Type", "application/json" }
                }
            };
            var _return = function.FunctionHandler(apiGateway, context);

            Assert.Equal(200, _return.StatusCode);
        }
Exemplo n.º 31
0
 public FileModel(string handler, int size, string fileName, UploadModel model)
 {
     Name = fileName;
     Type = model.ContentType;
     Size = size;
     Progress = "1.0";
     Url = HandlerPath + handler + "?g=" + model.Group + "&p=" + model.Url + "&f=" + fileName;
     ThumbnailUrl = model.UrlImageSmall + fileName;
     DeleteUrl = HandlerPath + handler + "?g=" + model.Group + "&p=" + model.Url + "&f=" + fileName;
     DeleteType = "DELETE";
 }
Exemplo n.º 32
0
        public ActionResult File()
        {
            var model = new UploadModel();
            model.OutputFormats = new List<SelectListItem> {
                new SelectListItem { Selected = true, Text = "Best guess, based upload", Value = OutputFormat.Unknown.ToString() },
                new SelectListItem { Text = "Android XML files", Value = OutputFormat.AndroidXml.ToString() },
                new SelectListItem { Text = "iOS PList files", Value = OutputFormat.PList.ToString() },
                new SelectListItem { Text = "Microsoft ResX files", Value = OutputFormat.ResX.ToString() },
                new SelectListItem { Text = "iOS Strings files", Value = OutputFormat.Strings.ToString() },
                //new SelectListItem { Text = "iOS Custstom XML files", Value = OutputFormat.Xml.ToString() }
            };

            return View(model);
        }
Exemplo n.º 33
0
        private void ConvertInput(HttpContext context)
        {
            // Local variable declaration
            var request = new UploadModel();

            // Set request
            request.FileName = context.Request["f"];
            request.Url = context.Request["p"];
            request.Group = context.Request["g"];
            request.ContentType = "image/jpeg";

            // Convert data input
            DataHelper.ConvertInput(request, input);
        }
Exemplo n.º 34
0
        public ActionResult Upload(UploadModel model)
        {
            if (ModelState.IsValid)
            {
                ShopConfigInfo shopConfigInfo = BSPConfig.ShopConfig;

                shopConfigInfo.UploadServer = model.UploadServer == null ? "" : model.UploadServer;
                shopConfigInfo.UploadImgType = model.UploadImgType;
                shopConfigInfo.UploadImgSize = model.UploadImgSize * 1000;
                shopConfigInfo.WatermarkType = model.WatermarkType;
                shopConfigInfo.WatermarkQuality = model.WatermarkQuality;
                shopConfigInfo.WatermarkPosition = model.WatermarkPosition;
                shopConfigInfo.WatermarkImg = model.WatermarkImg == null ? "" : model.WatermarkImg;
                shopConfigInfo.WatermarkImgOpacity = model.WatermarkImgOpacity;
                shopConfigInfo.WatermarkText = model.WatermarkText == null ? "" : model.WatermarkText;
                shopConfigInfo.WatermarkTextFont = model.WatermarkTextFont;
                shopConfigInfo.WatermarkTextSize = model.WatermarkTextSize;
                shopConfigInfo.BrandThumbSize = model.BrandThumbSize;
                shopConfigInfo.ProductShowThumbSize = model.ProductShowThumbSize;
                shopConfigInfo.UserAvatarThumbSize = model.UserAvatarThumbSize;
                shopConfigInfo.UserRankAvatarThumbSize = model.UserRankAvatarThumbSize;

                BSPConfig.SaveShopConfig(shopConfigInfo);
                Emails.ResetShop();
                SMSes.ResetShop();
                AddAdminOperateLog("修改上传设置");
                return PromptView(Url.Action("upload"), "修改上传设置成功");
            }

            LoadFont();
            return View(model);
        }
Exemplo n.º 35
0
        public ActionResult Upload(UploadModel model)
        {
            Session["UploadStarted"] = DateTime.UtcNow;

            var addValues = Request.IsAuthenticated && !String.IsNullOrEmpty(model.Language);

            Stream inputStream;
            if (!TryGetInputStream(model.PostedFile, out inputStream))
            {
                ModelState.AddModelError("PostedFile", "Unable to read file");
                return new EmptyResult();
            }

            var fileName = GetFileName(model.PostedFile);
            var tables = MvcApplication.FileParser.ExtractStringTables(inputStream, fileName);

            MvcApplication.TranslationService.AddKeysToDatabase(tables);

            if (addValues)
                MvcApplication.TranslationService.AddTranslationsToDatabase(tables, User, model.Language);

            OutputFormat outputFormat;
            if (!Enum.TryParse<OutputFormat>(model.SelectedOutputFormat, out outputFormat) || outputFormat == OutputFormat.Unknown)
                outputFormat = GuessOutputFormat(fileName);

            if (addValues)
            {
                TempData["Message"] = "Thank you for adding your knowledge to ours!";
                return RedirectToAction("Index", "Home");
            }

            var outputTables = MvcApplication.TranslationService.ProduceOutputTables(tables);
            var outputStream = MvcApplication.CompressionService.ProduceOutputStream(outputTables, outputFormat);

            Session["UploadEnded"] = DateTime.UtcNow;
            return File(outputStream, "application/zip", "translations.zip");
        }
        public ActionResult UploadDoc(string txtComment, string txtTokenNumber, string txtArogyaID, string txtComplaintID, int txtUserID)
        {
            try
            {
                var fileName = "";
                if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetFileName(file.FileName);
                        var path = Path.Combine(Server.MapPath(ConfigurationSettings.AppSettings["DocumentUploadPath"]), fileName);
                        file.SaveAs(path);
                    }

                    UploadModel upload = new UploadModel
                    {
                        Active = true,
                        ArogyaID = txtArogyaID,
                        Comments = txtComment,
                        ComplaintID = txtComplaintID == "" ? (int?)null : Convert.ToInt32(txtComplaintID),
                        CreateDate = DateTime.Now,
                        FileName = fileName,
                        Token_Number = txtTokenNumber == "" ? (int?)null : Convert.ToInt32(txtTokenNumber),
                        UserID = txtUserID
                    };

                    int count = new UploadDocumentsBll().SaveUpload(upload);

                    if (count > 0)
                        TempData["Success"] = "Upload Successful";
                    else
                        TempData["Success"] = "Upload failed";
                }
                else
                {
                    TempData["Success"] = "Please select a valid file to upload";
                }
            }
            catch (Exception ex)
            {
                TempData["Success"] = "Upload failed";
            }
            return RedirectToAction("UploadDocuments", new { tokenNumber = txtTokenNumber, arogyaID = txtArogyaID, complaintID = txtComplaintID, userID = txtUserID }); //View();
        }
Exemplo n.º 37
0
        private static void Main(string[] args)
        {
            //Specify this setting in the app.config file, under the appSetting key "api/clientid"
            _clientId = ConfigurationManager.AppSettings["api/clientid"];

            //Specify these setting in the app.config file, under the appSetting key "api/address" & "api/username"
            _api = new Api(ConfigurationManager.AppSettings["api/address"], _clientId, ConfigurationManager.AppSettings["api/username"]);

            //Specify this setting in the app.config file, under the appSetting key "api/password"
            _api.Authenticate(ConfigurationManager.AppSettings["api/password"]);

            // Typical routing integration workflow

            // The fastest way to creata a route is by using a template
            // In this scenario we are create a template using the API, however this can also be done through the front end
            // Typically you would have a template per branch/depot in a milk run scenario
            var templateId = "110/00983cfd-0131-4a52-9f44-64a3738662f5";

            // Create a list of DECO's to be uploaded
            var decos = new List<OLocation>
            {
                Decos.SandtonCity(_clientId),
                Decos.TheCampus(_clientId),
                Decos.FourwaysMall(_clientId),
                Decos.Adhoc(_clientId, "My New Adhoc Deco", "MNAD")
            };

            // Create a list of actions to be uploaded
            var actions = new[]
            {
                Actions.Collection(_clientId, decos[0], "4ACTION0_1"),
                Actions.Collection(_clientId, decos[0], "4ACTION0_2"),
                Actions.Collection(_clientId, decos[0], "4ACTION0_3"),
                Actions.Collection(_clientId, decos[0], "4ACTION0_4"),
                Actions.Collection(_clientId, decos[1], "4ACTION0_5"),
                Actions.Collection(_clientId, decos[1], "4ACTION0_6"),
                Actions.Collection(_clientId, decos[1], "4ACTION0_7"),
                Actions.Collection(_clientId, decos[1], "4ACTION0_8"),
                Actions.Collection(_clientId, decos[1], "4ACTION0_9")
            };

            // Create a list of entities to be uploaded
            var entities = new[]
            {
                Entities.Entity(_clientId, "entity/demo/1", "Entity 1", e =>
                {
                    // Requirements describe what the driver will be requried to capture when completing an entity visit
                    // This is only applicable if infinity devices are being used
                    e.Requirements = new ObservableCollection<EntityRequirement>()
                    {
                        new RequireRating
                        {
                            Ratings = new List<RatingDescription>
                            {
                                new RatingDescription {Name = "Service", Type = "Simple"}
                            }
                        }
                    };

                }),

                Entities.Entity(_clientId, "entity/demo/2", "Entity 2", e =>
                {
                    e.Requirements = new ObservableCollection<EntityRequirement>
                    {
                        new RequireActionDebrief(),
                        new RequireRating
                        {
                            Ratings = new List<RatingDescription>
                            {
                                new RatingDescription {Name = "Service", Type = "Smiley"}
                            }
                        },
                    };

                }),

                Entities.Entity(_clientId, "entity/demo/3", "Entity 3", e =>
                {

                    e.Requirements = new ObservableCollection<EntityRequirement>();
                }),

                Entities.Entity(_clientId, "entity/demo/4", "Entity 4", e =>
                {
                    e.Requirements = new ObservableCollection<EntityRequirement>();
                }),

                Entities.Entity(_clientId, "entity/demo/5", "Entity 5", e =>
                {
                    e.Requirements = new ObservableCollection<EntityRequirement>();
                })
            };

            // Create the relationships between the various components
            var relationships = new[]
            {
                Relationship.Link(actions[0]).To(entities[0]).At(decos[0]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
                Relationship.Link(actions[1]).To(entities[0]).At(decos[0]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
                Relationship.Link(actions[2]).To(entities[1]).At(decos[0]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
                Relationship.Link(actions[3]).To(entities[1]).At(decos[0]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
                Relationship.Link(actions[4]).To(entities[2]).At(decos[1]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
                Relationship.Link(actions[5]).To(entities[2]).At(decos[1]).OnRun(0).Customise(x =>
                {
                    x.Mst = TimeSpan.FromMinutes(8);

                    x.LockBefore = true;
                }),
                Relationship.Link(actions[6]).To(entities[3]).At(decos[1]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
                Relationship.Link(actions[7]).To(entities[3]).At(decos[2]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
                Relationship.Link(actions[8]).To(entities[4]).At(decos[3]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8))
            };

            // Descriptors allow you to customise how the Trackmatic API processes the data
            // Each field has an associated descriptor which allows you to set the authority and default value
            // The authority determines which system owns the information. If the authority is set to Trackmatic
            // and the component exists in trackmatic, the field will not be overwritten.
            // If the authority is set to Lob the field will be overwritten regardless of whether or not it exists in trackmatic
            // A descriptor can have other configuration values depending in the field type
            // The LocationStructuredAddressDescriptor for instance has multiple options to allow you to control geocoding rules.
            // The example below tells trackmatic to overwrite values with what is sent from line of business, sets the geocoding proximity
            // to 50km, set the result radius to 500m (when there is a match it will set the deco shape to a radius with the supplied radius value)

            var descriptors = new List<FieldDescriptorBase>
            {
                new LocationCoordsDescriptor
                {
                    Authority = EAuthority.Trackmatic
                },

                new EntityRequirementsDescriptor
                {
                    Authority = EAuthority.Lob
                },

                new RelationshipMstDescriptor
                {
                    Authority = EAuthority.Lob
                }
            };

            var reference = "DEMO110";

            // Upload various components and create route
            // Note: in order to just upload DECO's entities and actions just ignore the Route field
            var request = new UploadModel
            {
                Actions = actions.ToList(),
                Decos = decos.ToList(),
                Entities = entities.ToList(),
                Relationships = relationships.ToList(),
                Route = new RouteModel
                {
                    StartDate = DateTime.UtcNow,
                    Id = $"{_clientId}/{reference}",
                    TemplateId = templateId,
                    Reference = reference,
                    Registration = "BR31CMGP",
                    Name = "My New Route Name",
                    Options = new RouteOptions
                    {
                        AutomatedAdjustment = new AutomatedAdjustmentOptions
                        {
                            Enabled = true,

                            Threshold = TimeSpan.FromMinutes(15)
                        },
                        Lock = new LockOptions
                        {
                            All = true,
                            Start = true,
                            End = true
                        },
                        MaxSpeed = 100,
                        Strategy = ERouteStrategy.Shortest,
                        Temperature = 100
                    },
                    DueTimeAdjustments = new List<DueTimeAdjustmentModel>
                    {
                        new DueTimeAdjustmentModel
                        {
                            Adjustment = TimeSpan.FromMinutes(30),

                            Position = new End(),

                            Type = EDueTimeAdjustmentType.Layover
                        }
                    },
                    Schedule = false

                },
                Descriptors = descriptors
            };

            var json = request.ToJson(true);

            var start = DateTime.UtcNow;

            Console.WriteLine(start);

            var response = _api.ExecuteRequest(new Upload(_api.Context, request)).Data;

            Console.WriteLine(DateTime.UtcNow.Subtract(start));

            Console.ReadLine();

            //// Optmise can be called on the route many times
            //// This is only really required if you add/remove DECOS and you require the order to the DECO's to be optmised again
            //response = Optimise(response.Instance);

            //// Set lock all to true to prevent re-ordering of the decos
            //// and allow users to change the order manually
            //response.Instance.Route.LockAll = true;

            //var secondStop = response.Instance.Route.RouteDecos[2];

            //// Move 2nd stop to the last stop
            //response.Instance.Route.MoveDown(secondStop);

            //secondStop = response.Instance.Route.RouteDecos[2];

            //// Move 2nd stop to 1st position
            //response.Instance.Route.MoveUp(secondStop);

            //// The save method will perform an optmisation on the route automatically
            //Save(response.Instance);
        }
Exemplo n.º 38
0
        public ActionResult Upload()
        {
            ShopConfigInfo shopConfigInfo = BSPConfig.ShopConfig;

            UploadModel model = new UploadModel();
            model.UploadServer = shopConfigInfo.UploadServer;
            model.UploadImgType = shopConfigInfo.UploadImgType;
            model.UploadImgSize = shopConfigInfo.UploadImgSize / 1000;
            model.WatermarkType = shopConfigInfo.WatermarkType;
            model.WatermarkQuality = shopConfigInfo.WatermarkQuality;
            model.WatermarkPosition = shopConfigInfo.WatermarkPosition;
            model.WatermarkImg = shopConfigInfo.WatermarkImg;
            model.WatermarkImgOpacity = shopConfigInfo.WatermarkImgOpacity;
            model.WatermarkText = shopConfigInfo.WatermarkText;
            model.WatermarkTextFont = shopConfigInfo.WatermarkTextFont;
            model.WatermarkTextSize = shopConfigInfo.WatermarkTextSize;
            model.BrandThumbSize = shopConfigInfo.BrandThumbSize;
            model.ProductShowThumbSize = shopConfigInfo.ProductShowThumbSize;
            model.UserAvatarThumbSize = shopConfigInfo.UserAvatarThumbSize;
            model.UserRankAvatarThumbSize = shopConfigInfo.UserRankAvatarThumbSize;

            LoadFont();
            return View(model);
        }