I am uploading an image from my android device to my ASP.NET MVC server.
The save path I would like to use is
HttpContext.Server.MapPath("../") + "App_Data/" + HttpContext.User.Identity.Name + model.Firstname + "-" + model.Surname
+ "-" + System.IO.Path.GetFileName(Request.Files[0].FileName);
Which should give /App_Data/AccountName/firstname-surname-filename.jpg
This works for me when I do this within the MVC itself using
@Html.LabelFor(m => m.Firstname)
@Html.TextBoxFor(m => m.Firstname)
@Html.LabelFor(m => m.Surname)
@Html.TextBoxFor(m => m.Surname)
<label for="file1">Upload Image</label>
<input type="file" name="picture" id="picture" />
<input type="submit" />
In order to execute the upload from the Android Application I need to use javascript from within the MVC as follows
<script type="text/javascript">
function showAndroidToast(toast)
{
Android.showToast(toast);
}
</script>
<input type="submit" value="Scan Fingerprint" onClick="showAndroidToast('Scanning fingerprint')" />'
Where the showToast function is the upload function in my android application.
I can get the image to upload from the android but even though I have logged into my ASP.NET application, the save path doesn't work for the HttpContext.User.Identity.Name which I need to work at the bare minimum. If I add [Authorize] to my upload controller as well, the upload won't work which further suggests it isn't using the log-in information.
Is it possible to do this when uploading from an Android device to the ASP.NET web service?