开发者

Display image from memory using file upload

开发者 https://www.devze.com 2022-12-24 08:20 出处:网络
So I\'m working on a site that is going to need a file upload control where the user would be able to upload an image, and then the page would postback causing the image to appear for their viewing (b

So I'm working on a site that is going to need a file upload control where the user would be able to upload an image, and then the page would postback causing the image to appear for their viewing (before they submit the data to the database, the image is being stored as type开发者_StackOverflow image). What I do now is have my own private web form where people send me their image, I format it accordingly and use the following simple code to upload it:

byte[] newimage = fileUpImgFile.FileBytes;
var myDataTable = (from item in context.TypeSet where item.Number == txtBxNumber.Text.Trim() select item).ToList();

foreach (Type item in myDataTable)
{
    item.Photo = newimage;
}
context.SaveChanges();

Which works, but in this case, it would only work if the record exists already in the database so the person would have to save the data, then go back in and upload the image (inconvenient and inefficient). Is there a way to upload it, store it in memory, and then display it, without saving it to the database?


Once you have the uploaded bytes, you can do anything you want with it.

The approach that immediately jumps to mind is storing the bytes in Session for that user.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号