I have an ASP File upload, PostedFile.InputStream, it is giving us the System.IO.Stream. Is this file stream similar to that of getting

System.IO.File.OpenRead("filename");

I have a Rackspace file content saver that gets the input as Stream, it's not getting the correct image displayed when used PostedFile.InputStream.

有帮助吗?

解决方案

Normally PostedFile.InputStream and System.IO.Stream are same. So there is no need of any additional coding for Rackspace.

You can use file.InputStream as the Stream parameter to create the Object of Rackspace cloud files.

Another method which is not required but can test is

byte[] buffer = new byte[file.InputStream.Length];
file.InputStream.Seek(0, SeekOrigin.Begin);
file.InputStream.Read(buffer, 0, Convert.ToInt32(file.InputStream.Length));
Stream stream2 = new MemoryStream(buffer);

You can use this stream also as input for creating object.

其他提示

This one worked with rackspace cloud , It can upload file from client side to rackspace cloud file. I also used file uploader.

protected void Button1_Click(object sender, EventArgs e)
        {
            var cloudIdentity = new CloudIdentity() { Username = "Rackspace_user_name", APIKey = "Rackspace_api" };
            var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);


            byte[] buffer = new byte[FileUpload1.FileBytes.Length];
            FileUpload1.FileContent.Seek(0, SeekOrigin.Begin);
            FileUpload1.FileContent.Read(buffer, 0, Convert.ToInt32(FileUpload1.FileContent.Length));
            Stream stream2 = new MemoryStream(buffer);
            try
            {
                using (FileUpload1.PostedFile.InputStream)
                {
                    cloudFilesProvider.CreateObject("Containers_name", stream2, FileUpload1.FileName); //blockBlob.UploadFromStream(fileASP.PostedFile.InputStream);
                }
            }

            catch (Exception ex)
            {



    Label1.Text = ex.ToString();

            }
        }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top