ASP FileUpload InputStream and System.IO.File.OpenRead

I have an ASP file upload, PostedFile.InputStream , it gives us System.IO.Stream . Is this file stream similar to getting

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

I have a content saver for a Rackspace file that receives input as a Stream, it does not receive the correct image displayed when using PostedFile.InputStream .

+4
source share
2 answers

Typically, PostedFile.InputStream and System.IO.Stream same. Therefore, there is no need for additional coding for Rackspace.

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

Another method that is not required but can be tested

 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 to create an object.

+2
source

This worked with the rackspace cloud; it can upload a file from the client side to the rackspace cloud file. I also used a file downloader.

 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(); } } 
0
source

Source: https://habr.com/ru/post/1495542/


All Articles