Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. **Web API code:**
  2.  
  3. [Route("api/[controller]")]
  4. [ApiController]
  5. public class ImageTestController : ControllerBase
  6. {
  7. //Image upload
  8. [HttpPost]
  9. public async Task<string> ImageUpload([FromForm]IFormFile file)
  10. {
  11. if (file.Length > 0)
  12. {
  13. try
  14. {
  15. if (!Directory.Exists("actualpath"))
  16. {
  17. Directory.CreateDirectory("actualpath");
  18. }
  19. using (FileStream filestream = System.IO.File.Create("actualpath" + file.FileName))
  20. {
  21. file.CopyTo(filestream);
  22. filestream.Flush();
  23. return file.FileName;
  24. }
  25. }
  26. catch (Exception ex)
  27. {
  28. return ex.ToString();
  29. }
  30. }
  31. else
  32. {
  33. return "Unsuccessful";
  34. }
  35.  
  36. }
  37. }
  38.  
  39.  
  40. **web application controller**
  41.  
  42. public class SampleController : Controller
  43. {
  44. [HttpPost]
  45. public ActionResult SavePhoto(IFormFile fileParameter)
  46. {
  47. //In fileParameter i will recieve the image
  48. and i need to send this to Web API
  49. }
  50. }
  51.  
  52. **.cshtml : containing kendo UI upload control**
  53.  
  54. <div class="demo-section k-content">
  55. @(Html.Kendo().Upload()
  56. .Name("files")
  57. .HtmlAttributes(new { aria_label = "files" } )
  58. .Multiple(false)
  59. .Async(a => a
  60. .Save("SavePhoto", "Sample")
  61. .AutoUpload(true)
  62. .SaveField("fileParameter")
  63.  
  64. ))
  65. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement