Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在angular 4中从asp.net web api加载图像?_Angular_Asp.net Web Api2 - Fatal编程技术网

如何在angular 4中从asp.net web api加载图像?

如何在angular 4中从asp.net web api加载图像?,angular,asp.net-web-api2,Angular,Asp.net Web Api2,我正在上传angular 4的一个图像,并将其存储在我的WebAPI项目的文件夹中。如何从后端获取这些映像?下面是将其存储在web api中的代码 [HttpPost] [Route("api/SaveFoodItemImage")] [AllowAnonymous] public HttpResponseMessage SaveFoodItemImage() { string imageName = null; var httpR

我正在上传angular 4的一个图像,并将其存储在我的WebAPI项目的文件夹中。如何从后端获取这些映像?下面是将其存储在web api中的代码

[HttpPost]
    [Route("api/SaveFoodItemImage")]
    [AllowAnonymous]
    public HttpResponseMessage SaveFoodItemImage()
    {
        string imageName = null;
        var httpRequest = HttpContext.Current.Request;         
        var postedFile = httpRequest.Files["Image"];         
        imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-");
        imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName);
        var filePath = HttpContext.Current.Server.MapPath("~/Image/" + imageName);
        postedFile.SaveAs(filePath);
        var uploadedImageId = httpRequest["FoodItemId"];           
        var foodItem = _context.FoodItems.FirstOrDefault(p => p.Id == uploadedImageId);
        foodItem.FoodItemImage = imageName;
        _context.SaveChanges();
        return Request.CreateResponse(HttpStatusCode.Created);
    }

如何在前端的对象中检索它们?

为什么不将“src”属性指向获取图像的api?src属性只获取前端的图像名称。它只显示图像名称,而不是对我来说没有意义的图像-也许你可以发布一段HTML和Angle代码?好的。我过一会儿再做。