问题
I've been searching for long time of solving the limitation in asp file uploading as the case in my question File Upload: Fail to assign value into File, it still not answered by anybody. At this moment, can i know is there anybody here know how to use session to store an image for temporary, and thereafter retrieve it back to the stream and put it into the model?
回答1:
You could convert the image into a byte array then convert it to a base64 string and save that into the session. Then convert it to a byte array and bind it to your control.
回答2:
I finally found the solution for it. ;)
if (model.File != null && model.File.ContentLength > 0)
{
Byte[] destination1 = new Byte[model.File.ContentLength];
model.File.InputStream.Position = 0;
model.File.InputStream.Read(destination1, 0, model.File.ContentLength);
model.BankSlip = destination1;
Session["info.file"]= model.File;//storing session.
}
else
{
//retrieving session
var myImg1 = Session["info.file"] as HttpPostedFileBase;
model.File = myImg1;
Byte[] data=new Byte[myImg1.ContentLength];
myImg1.InputStream.Position = 0;
myImg1.InputStream.Read(data, 0, myImg1.ContentLength);
model.BankSlip = data;
}
}
catch (Exception ex)
{
DepositControllerLog.ErrorException("DepositController - LocalBank(Post) - AddAttachment(refreshed) - ", ex);
}
}
来源:https://stackoverflow.com/questions/26132792/session-storing-images-for-temporary-and-retrive-and-store-into-model