Im trying to upload an image using a form, which is working. but i end up with a useless byte array, how can i translate it into an image object?..
The goal is to display the image on the same cshtml page.
@{
var status = "Ready for upload..";
if(IsPost){
var file = (HttpPostedFileBase) Request.Files[0];
string fileExt = System.IO.Path.GetExtension(file.FileName);
fileExt = fileExt.ToLower();
if(!( (fileExt == ".png") || (fileExt == ".jpg") )){
status = "Only JPG or PNG files allowed.";
Response.Write(status + " " + fileExt);
Response.End();
return;
}
string ContentType = "image/" + fileExt.Substring(1);
BinaryReader b = new BinaryReader(file.InputStream);
file.InputStream.Seek(0, SeekOrigin.Begin);
byte[] binData = b.ReadBytes(file.ContentLength);
Response.BinaryWrite(binData);
Response.End();
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>SWE-363 HW - 3</title>
</head>
<body>
<div>
<h1 style="color: #0094ff">
Choose a photo of type <em> (.png or jpg).. </em>
</h1>
<form method="POST" name="UPLOAD" enctype="multipart/form-data" action="hw3.cshtml">
<input type="file" name="newphoto">
<input type="submit" value="Upload File">
</form>
</div>
</body>
</html>
is there another way to display the feedback... other than "Response" ?
Aucun commentaire:
Enregistrer un commentaire