文件上传到的FileStream [英] FileUpload to FileStream

查看:189
本文介绍了文件上传到的FileStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与HttpWebRequest的一起发送文件的过程。我的文件将被从文件上传UI。在这里,我需要将文件上传转换为FILESTREAM与HttpWebRequest的一起发送流。如何将文件上传转换为FILESTREAM?

I am in process of sending the file along with HttpWebRequest. My file will be from FileUpload UI. Here i need to convert the File Upload to filestream to send the stream along with HttpWebRequest. How do i convert the FileUpload to a filestream?

推荐答案

由于FileUpload.PostedFile.InputStream给我流时,我用下面的code将其转换为字节数组

Since FileUpload.PostedFile.InputStream gives me Stream, I used the following code to convert it to byte array

public static byte[] ReadFully(Stream input)
{
    byte[] buffer = new byte[input.Length];
    //byte[] buffer = new byte[16 * 1024];
    using (MemoryStream ms = new MemoryStream())
    {
        int read;
        while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
        {
            ms.Write(buffer, 0, read);
        }
        return ms.ToArray();
    }
}

这篇关于文件上传到的FileStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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