Ejemplo n.º 1
0
 public Praticien Post([FromForm] Praticien praticien, [FromForm] IFormFile image)
 {
     praticien.Images.Add(new Image()
     {
         Url = _upload.Upload(image)
     });
     praticien.Save();
     return(praticien);
 }
Ejemplo n.º 2
0
        public void Build(Uri uri)
        {
            var htmlDocument = webClient.Download(uri);
            var wordDocument = documentConverter.ToWord(htmlDocument);

            iUpload.Upload(wordDocument);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <Category> > PostCategory([FromForm] IFormFile image, [FromForm][Bind("Title")] Category category)
        {
            category.Image = _upload.Upload(image);
            _context.Categories.Add(category);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCategory", new { id = category.Id }, category));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UploadImageAsync(IFormFile file, String type)
        {
            var filePath = await _uploadService.Upload(file, type);

            if (filePath != null)
            {
                return(Ok(filePath));
            }

            return(StatusCode(500, "Não foi possível realizar esta ação"));
        }
Ejemplo n.º 5
0
 public IActionResult SubmitFiles(IFormFile[] files)
 {
     if (_uploadService.Upload(files))
     {
         return(Ok(new { message = "All Ok" }));
     }
     else
     {
         return(Ok(new { message = "Error upload" }));
     }
 }
Ejemplo n.º 6
0
 public IActionResult SubmitFromAnnonce(Annonce annonce, IFormFile[] images)
 {
     foreach (IFormFile image in images)
     {
         annonce.Images.Add(new Image()
         {
             Url = _uploadService.Upload(image)
         });
     }
     annonce.Save();
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 7
0
        public IActionResult SubmitFromPraticien(Praticien praticien, IFormFile[] images)
        {
            foreach (IFormFile image in Request.Form.Files)
            {
                praticien.Images.Add(new Image()
                {
                    Url = _uploadSerice.Upload(image)
                });
            }
            praticien.Save();

            return(new JsonResult(new { error = false }));
            // return RedirectToAction("Index");
        }
Ejemplo n.º 8
0
        public JsonResult Upload(string collection = null, string ac = null)
        {
            IUpload UpOp    = WebIoc.Container.Resolve <IUpload>();
            var     context = ControllerContext.HttpContext;

            if (string.IsNullOrEmpty(ac))
            {
                ac = context.Request["action"];
            }
            switch (ac)
            {
            case "config": return(UploadConfig());

            case "uploadimage":
            {
                UploadResult result = UpOp.Upload(new UploadConfig()
                    {
                        AllowExtensions = CustomConfig.ImgExts.ToArray(),
                        PathFormat      = CustomConfig.EditorImgPath,
                        SizeLimit       = Convert.ToInt32(CustomConfig.CanUploadImgSize * 1024 * 1024),
                        UploadFieldName = "upfile"
                    });
                return(Json(new
                    {
                        fileid = result.FileId,
                        state = UpOp.GetStateMessage(result.State),
                        url = result.Url,
                        title = result.OriginFileName,
                        original = result.OriginFileName,
                        error = result.ErrorMessage
                    }, "text/html"));
            }

            case "uploadscrawl":
            {
                UploadResult result = UpOp.Upload(new UploadConfig()
                    {
                        AllowExtensions = CustomConfig.ImgExts.ToArray(),
                        PathFormat      = CustomConfig.EditorImgPath,
                        SizeLimit       = Convert.ToInt32(CustomConfig.CanUploadImgSize * 1024 * 1024),
                        UploadFieldName = "upfile",
                        Base64          = true,
                        Base64Filename  = "scrawl.png"
                    });
                return(Json(new
                    {
                        fileid = result.FileId,
                        state = UpOp.GetStateMessage(result.State),
                        url = result.Url,
                        title = result.OriginFileName,
                        original = result.OriginFileName,
                        error = result.ErrorMessage
                    }, "text/html"));
            }

            case "uploadvideo":
            {
                UploadResult result = UpOp.Upload(new UploadConfig()
                    {
                        AllowExtensions = CustomConfig.VideoExts.ToArray(),
                        PathFormat      = CustomConfig.EditorFilePath,
                        SizeLimit       = Convert.ToInt32(CustomConfig.CanUploadFileSize * 1024 * 1024),
                        UploadFieldName = "upfile",
                    });
                return(Json(new
                    {
                        fileid = result.FileId,
                        state = UpOp.GetStateMessage(result.State),
                        url = result.Url,
                        title = result.OriginFileName,
                        original = result.OriginFileName,
                        error = result.ErrorMessage
                    }, "text/html"));
            }

            case "uploadfile":
            {
                UploadResult result = UpOp.Upload(new UploadConfig()
                    {
                        AllowExtensions = CustomConfig.FileExts.ToArray(),
                        PathFormat      = CustomConfig.EditorFilePath,
                        SizeLimit       = Convert.ToInt32(CustomConfig.CanUploadFileSize * 1024 * 1024),
                        UploadFieldName = "upfile",
                    });
                return(Json(new
                    {
                        fileid = result.FileId,
                        state = UpOp.GetStateMessage(result.State),
                        url = result.Url,
                        title = result.OriginFileName,
                        original = result.OriginFileName,
                        error = result.ErrorMessage
                    }, "text/html"));
            }

            case "listimage":
            {
                int                  Start = 0, Size = 20, Total = 300;
                ResultState          State   = ResultState.Success;
                IEnumerable <String> imgList = null;
                Start = String.IsNullOrEmpty(Request["start"]) ? 1 : Convert.ToInt32(Request["start"]);
                Size  = String.IsNullOrEmpty(Request["size"]) ? 20 : Convert.ToInt32(Request["size"]);
                try
                {
                    var path = collection;
                    if (string.IsNullOrEmpty(collection))
                    {
                        path = CustomConfig.EditorImgPath + DateTime.Now.ToString("yyyy/MM/");
                    }
                    imgList = UpOp.GetFiles(path, "", Start, Size);
                    if (string.IsNullOrEmpty(collection))
                    {
                        imgList = imgList.Select(x => path + x);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    State = ResultState.AuthorizError;
                }
                catch (DirectoryNotFoundException)
                {
                    State = ResultState.PathNotFound;
                }
                catch (IOException)
                {
                    State = ResultState.IOError;
                }
                return(Json(new
                    {
                        state = GetStateString(State),
                        list = imgList.Select(x => new { url = x }),
                        start = Start,
                        size = Size,
                        total = Total
                    }, JsonRequestBehavior.AllowGet));
            }

            case "listfile":
            {
                int                  Start = 0, Size = 20, Total = 300;
                ResultState          State    = ResultState.Success;
                IEnumerable <String> fileList = null;
                Start = String.IsNullOrEmpty(Request["start"]) ? 0 : Convert.ToInt32(Request["start"]);
                Size  = String.IsNullOrEmpty(Request["size"]) ? 20 : Convert.ToInt32(Request["size"]);
                try
                {
                    var path = collection;
                    if (string.IsNullOrEmpty(collection))
                    {
                        path = CustomConfig.EditorImgPath + DateTime.Now.ToString("yyyy/MM/");
                    }
                    fileList = UpOp.GetFiles(path, "", Start, Size);
                    if (string.IsNullOrEmpty(collection))
                    {
                        fileList = fileList.Select(x => path + x);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    State = ResultState.AuthorizError;
                }
                catch (DirectoryNotFoundException)
                {
                    State = ResultState.PathNotFound;
                }
                catch (IOException)
                {
                    State = ResultState.IOError;
                }
                return(Json(new
                    {
                        state = GetStateString(State),
                        list = fileList.Select(x => new { url = x }),
                        start = Start,
                        size = Size,
                        total = 0
                    }, JsonRequestBehavior.AllowGet));
            }

            case "catchimage":
            {
                string[]   Sources;
                CatchImg[] Crawlers;
                Sources = Request.Form.GetValues("source[]");
                if (Sources == null || Sources.Length == 0)
                {
                    return(Json(new { state = "参数错误:没有指定抓取源" }));
                }
                else
                {
                    Crawlers = Sources.Select(x => new CatchImg(x, context.Server).Fetch(CustomConfig.EditorImgPath)).ToArray();
                }
                return(Json(new
                    {
                        state = "SUCCESS",
                        list = Crawlers.Select(x => new
                        {
                            state = x.State,
                            source = x.SourceUrl,
                            url = x.ServerUrl
                        })
                    }, JsonRequestBehavior.AllowGet));
            }

            default:
                return(Json(new { state = "action 参数为空或者 action 不被支持。" }));
            }
        }