We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Unable to stream xlsx doc from S3 Bucket

Thread ID:

Created:

Updated:

Platform:

Replies:

144854 May 26,2019 03:46 AM UTC May 28,2019 06:53 AM UTC ASP.NET Web Forms 3
loading
Tags: XlsIO
Ryan
Asked On May 26, 2019 03:46 AM UTC

I am trying to pull down a xlsx document from a s3 bucket and it keeps failing with an error -
{"Zip exception.Unable to read value at the specified position - end of stream was reached."} Syncfusion.Compression.Zip.ZipException but the item it is pulling down is not a zip document 

        protected void reportfunction_Click(object sender, EventArgs e)
        {
            {
                ExcelEngine excelEngine = new ExcelEngine();
                
                IWorkbook workbook = excelEngine.Excel.Workbooks.Open(getobject());
                IWorksheet sheet = workbook.Worksheets[0];
                sheet.Range["O1"].Text = "Editing the O1";

                //Saves and closes the document instance

                workbook.SaveAs(@"C:\Users\" + Environment.UserName + @"\Desktop\Result.xlsx");

                workbook.Close();

                System.Diagnostics.Process.Start(@"C:\Users\" + Environment.UserName + @"\Desktop\Result.xlsx");

            }
        }
The code I am using to get the xlsx doc is below.  ** Note I was able to use this to successfully pull down a docx file and make changes with SyncFusion. **
        private Stream getobject()
        {
            using (AmazonS3Client client = new AmazonS3Client(RegionEndpoint.USEast1))
            {
                GetObjectResponse getObjRespone = client.GetObject("bucketname", "filename.xlsx");
                MemoryStream stream = new MemoryStream();
                getObjRespone.ResponseStream.CopyTo(stream);
                return stream;
            }
        }

I tried to add in FileStream inputStream = getobject() as FileStream; but it told me that it could not read a null value.

If replace the getobject() in the excelEngine.Excel.Workbooks.Open(getobject()); with a local copy of the file it does work and edit the file correctly.

Anyone have any ideas? 

Thanks! 

Abirami Varadharajan [Syncfusion]
Replied On May 27, 2019 09:35 AM UTC

Hi Ryan, 

Greetings from Syncfusion. 

As the stream reached end position while copying, the exception is raised at your end. You can reset the stream position as `0` to resolve this issue. Please find below code for the same. 

Code Example: 
private Stream getobject() 
        { 
            using (AmazonS3Client client = new AmazonS3Client(RegionEndpoint.USEast1)) 
            { 
                GetObjectResponse getObjRespone = client.GetObject("bucketname", "filename.xlsx"); 
                MemoryStream stream = new MemoryStream(); 
                getObjRespone.ResponseStream.CopyTo(stream); 
                stream.Position = 0; 
                return stream; 
            } 
        } 

Kindly try this and let us know if this resolve the issue. 

Regards, 
Abirami 


Ryan
Replied On May 27, 2019 04:42 PM UTC

Thank you that worked perfectly. 

Abirami Varadharajan [Syncfusion]
Replied On May 28, 2019 06:53 AM UTC

Hi Ryan, 

We are glad that it worked fine at your end.  

Please get back to us know if you need further assistance. 

Regards, 
Abirami. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon