I want to convert a URL like http://localhost/app/Uploads/file.png
to my application virtual path, i.e., ~/Uploads/file.txt
.
My question is how can it be done in asp net mvc?
EDIT: some explanation on my scenario for further clarification.
I have a "Create" form. In this form, the user sets up its profile and can upload a photo to the server. This photo can be previewed by async uploading it to the server. This is accomplished by the action Post() of the FileUploadController, which is an ApiController. This action simply saves the uploaded file to the virtual path "~/Uploads/" and then returns the full URL to the saved file, something like http://localhost/app/Uploads/file.png
. Then, the javascript on the page catches this url and updates a <img>
tag to display the picture and sets the value of an hidden input field with this URL. This works fine.
Now, I have to implement the Submit action of this "Create" form. Among other things, the action viewmodel receives the URL of the photo, i.e., http://localhost/app/Uploads/file.png
, which should be used to copy the file 'file.png' from the temporary location "~/Uploads/file.png" to another location. However, to Copy this file, I need the local path to it and all I have is the URL.