being fab
being fab

Reputation: 667

How to get the path of image source before uploading in mvc?

I want to get the path of the image from where it is being uploaded...

Ex:my image is in E:drive and in images folder and i want to get that path before i upload the image

My Controllercode is below

    public ActionResult UploadImage(UploadImageModel model)
    {

        if (ModelState.IsValid)
        {

            Bitmap original = null;
            var name = "newimagefile";
            var errorField = string.Empty;

            if (model.IsUrl)
            {
                errorField = "Url";
                name = GetUrlFileName(model.Url);
                original = GetImageFromUrl(model.Url);
            }
            else if (model.IsFlickr)
            {
                errorField = "Flickr";
                name = GetUrlFileName(model.Flickr);
                original = GetImageFromUrl(model.Flickr);
            }
            else if (model.File != null) 
            {

                errorField = "File";
                name = Path.GetFileNameWithoutExtension(model.File.FileName);
                original = Bitmap.FromStream(model.File.InputStream) as Bitmap;
            }


            if (original != null)
            {
                var img = CreateImage(original, model.X, model.Y, model.Width, model.Height);


                var fn = Server.MapPath("~/Content/img/" + name + ".png");
                img.Save(fn, System.Drawing.Imaging.ImageFormat.Png);


                return RedirectToAction("Index");
            }
            else 
                ModelState.AddModelError(errorField, "Your upload did not seem valid. Please try again using only correct images!");
        }

        return View(model);
    }

Upvotes: 0

Views: 1279

Answers (1)

Hrishi
Hrishi

Reputation: 350

it is not possible . it is a security threat if the browser sends the full path from client side.

Upvotes: 1

Related Questions