Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromFile] UserFile file)
        {
            if (file == null || !file.IsValid)
            {
                return(new JsonResult(new { code = 500, message = "不允许上传的文件类型" }));
            }
            string newFile = string.Empty;

            if (file != null)
            {
                newFile = await file.SaveAs("/data/files/images");
            }
            return(new JsonResult(new { code = 0, message = "成功", url = newFile }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UseFormAttributeUpload([FromForm] UserFile file, [FromServices] IWebHostEnvironment environment)
        {
            if (file == null || !file.IsValid)
            {
                return(BadRequest("不允许上传的文件类型"));
            }
            if (file == null)
            {
                return(BadRequest("请选择上传文件"));
            }
            var    today      = DateTime.Today.ToString("yyyyMMdd");
            var    baseFolder = fileFolderBaseName + @"/" + today;
            string folderPath = Path.Combine(environment.WebRootPath, baseFolder);
            string fileName   = await file.SaveAs(folderPath);

            return(Ok(baseFolder + "/" + fileName));
        }
Exemplo n.º 3
0
        public async Task <string> Post([FromFile] UserFile file)
        {
            if (file == null || !file.IsValid)
            {
                return("请选择合适的文件");
            }

            string newFile = string.Empty;

            if (file != null)
            {
                newFile = await file.SaveAs("/data/files/images");
            }

            return("处理成功");
            //return new JsonResult(new { code = 0, message = "成功", url = newFile });
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Post([FromFile] UserFile file)
        {
            string webRootPath     = _hostingEnvironment.WebRootPath;
            string contentRootPath = _hostingEnvironment.ContentRootPath;

            if (file == null || !file.IsValid)
            {
                return(new JsonResult(new { code = 500, message = "不允许上传的文件类型" }));
            }
            string newFile = string.Empty;

            if (file != null)
            {
                newFile = await file.SaveAs(_hostingEnvironment.WebRootPath, "/images");
            }

            return(new JsonResult(new { code = 0, message = "成功", url = newFile }));
        }