临时存储图像的会话并检索并存储到模型中 [英] Session Storing Images for Temporary and retrive and store into model

查看:96
本文介绍了临时存储图像的会话并检索并存储到模型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找解决 asp文件上传 中的限制的时间很长的方法,例如我的问题

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?

推荐答案

我终于找到了解决方案. ;)

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);
        }
        }

这篇关于临时存储图像的会话并检索并存储到模型中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆