0

I'm uploading photos to a external library and the API to this library needs the path to the file I'm uploading.

Here is my Code:

    public ActionResult UploadImageToCloudinary(HttpPostedFileBase file, string group, string filter)
    {

        if (file != null && file.ContentLength > 0)
        {
            // extract only the fielname
            var fileName = Path.GetFileName(file.FileName);
            if (fileName != null)
            {
                // get path including filename
                var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);

               // other unimportant logic

        }


        return Content("Fail");
    }

I've done this, but obviously it can't find it according to "~/App_Data/uploads" It returns D:\Visual Studio Projects\Impola\Somefilder1\Somfolder2\App_Data\uploads\cara.jpg

and the real filepath is D:\MyProjects\Images\cara.jpg which is the one I need.

How to get the real filepath?

user3228992
  • 1,373
  • 1
  • 16
  • 31
  • You getting that path because your running you app from VS. When you publish it you will get a different path. Not sure what you mean by _the real filepath is D:\MyProjects\Images\cara.jpg_ –  Apr 02 '16 at 10:37

1 Answers1

0

Simply, you can change the path to specific folder you want. You should create the folder "Images" in your application to avoid error. In production, make sure you set write permission to your application to the "Images" folder.

var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
samvietnam
  • 16
  • 2