Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **Web API code:**
- [Route("api/[controller]")]
- [ApiController]
- public class ImageTestController : ControllerBase
- {
- //Image upload
- [HttpPost]
- public async Task<string> ImageUpload([FromForm]IFormFile file)
- {
- if (file.Length > 0)
- {
- try
- {
- if (!Directory.Exists("actualpath"))
- {
- Directory.CreateDirectory("actualpath");
- }
- using (FileStream filestream = System.IO.File.Create("actualpath" + file.FileName))
- {
- file.CopyTo(filestream);
- filestream.Flush();
- return file.FileName;
- }
- }
- catch (Exception ex)
- {
- return ex.ToString();
- }
- }
- else
- {
- return "Unsuccessful";
- }
- }
- }
- **web application controller**
- public class SampleController : Controller
- {
- [HttpPost]
- public ActionResult SavePhoto(IFormFile fileParameter)
- {
- //In fileParameter i will recieve the image
- and i need to send this to Web API
- }
- }
- **.cshtml : containing kendo UI upload control**
- <div class="demo-section k-content">
- @(Html.Kendo().Upload()
- .Name("files")
- .HtmlAttributes(new { aria_label = "files" } )
- .Multiple(false)
- .Async(a => a
- .Save("SavePhoto", "Sample")
- .AutoUpload(true)
- .SaveField("fileParameter")
- ))
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement