Пример #1
0
        public IActionResult UploadImage([FromServices] WtmFileProvider fp, int?width = null, int?height = null, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
        {
            if (width == null && height == null)
            {
                return(Upload(fp, sm, groupName, csName));
            }
            var FileData = Request.Form.Files[0];

            Image oimage = Image.FromStream(FileData.OpenReadStream());

            if (oimage == null)
            {
                return(BadRequest(Localizer["Sys.UploadFailed"]));
            }
            if (width == null)
            {
                width = height * oimage.Width / oimage.Height;
            }
            if (height == null)
            {
                height = width * oimage.Height / oimage.Width;
            }
            MemoryStream ms = new MemoryStream();

            oimage.GetThumbnailImage(width.Value, height.Value, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            ms.Position = 0;
            var file = fp.Upload(FileData.FileName, FileData.Length, ms, groupName, subdir, extra, sm, Wtm.CreateDC(cskey: csName));

            oimage.Dispose();
            ms.Dispose();

            if (file != null)
            {
                return(Ok(new { Id = file.GetID(), Name = file.FileName }));
            }
            return(BadRequest(Localizer["Sys.UploadFailed"]));
        }
Пример #2
0
        public IActionResult Upload([FromServices] WtmFileProvider fp, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
        {
            var FileData = Request.Form.Files[0];
            var file     = fp.Upload(FileData.FileName, FileData.Length, FileData.OpenReadStream(), groupName, subdir, extra, sm, Wtm.CreateDC(cskey: csName));

            return(Ok(new { Id = file.GetID(), Name = file.FileName }));
        }