Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to save an image in the web API folder by postman and I received the status code ok, but the image file does not save . is there any problem with my code?
*ignore save in db part please *

[HttpPost]
    public HttpResponseMessage AddItem()
    {
        string mypath = HttpContext.Current.Server.MapPath("~/images");

        if (!Directory.Exists(mypath))
        {
            Directory.CreateDirectory(mypath);
        }
        //Fetch the File.
        HttpPostedFile postedFile =  HttpContext.Current.Request.Files[0];
        //Fetch the File Name.
        string fileName = Path.GetFileName(postedFile.FileName);
        //Save the File.
         postedFile.SaveAs(mypath + fileName);

         
       
        string TfoodType = HttpContext.Current.Request.Form["foodType"];
       
        string TfoodName = HttpContext.Current.Request.Form["foodName"];
       
        int TfoodPrice = Convert.ToInt32(HttpContext.Current.Request.Form["foodPrice"]);
       
         string TfoodDescription = HttpContext.Current.Request.Form["foodDescription"];
       


      //save values in database

        using (var context = new ModelFoodDb() )
            {
                context.fooditem.Add(new FoodItems()
                {

                    //  foodType = FM.foodType ,
                   // foodName = FM.foodName ,
                  //  foodPrice = FM.foodPrice ,
                  //  foodDescription = FM.foodDescription,
                  //  foodImage = FM.foodImage
                });
                context.SaveChanges();
            }

        
        return Request.CreateResponse(HttpStatusCode.OK, fileName);

    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
262 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...