4

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.

Rich
  • 5,603
  • 9
  • 39
  • 61
Prem Singh
  • 1,035
  • 3
  • 13
  • 31
  • Does this work locally? – Mike Perrenoud Aug 06 '13 at 13:50
  • If used correctly, you should be able to read the data the same way from any object inheriting from `System.IO.Stream`. Can you show the code that you use to read the data? A common mistake for example is ignoring the return value when using the `Read` method. – Guffa Aug 06 '13 at 14:17
  • Can you provide more details? In particular: 1) code showing your use of the "rackspace file content saver", 2) code showing your use of streams to upload and download the file. – Sam Harwell Aug 06 '13 at 14:28

2 Answers2

3

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.

Liya S
  • 439
  • 4
  • 13
0

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

            }
        }