Error when streaming multiple Documents

Good day


When trying to stream multiple files "18" I get "index was outside the bounds of the array"


I get the error on the below code

(Viewer.ClientCode()
.TargetElementSelector("#MainViewerWindow")
.Streams(this.streamDefinitions,this.DownloadFileName)
.OpenThumbnails(false)
.SupportPageRotation(true)
.ShowFolderBrowser(false)
.PreloadPagesCount(1)
.ZoomToFitHeight())

I am using groupdocs 2.12


Kind regards
Divan

Hello Divan,


We are sorry to hear that you have such issue. Please check this code example for how to view several streams:

In the beck-end code:
const string testFilesDir = “~/testfiles/”;
string[] filePaths ={
@Server.MapPath(testFilesDir + “timesheet.xls”),
@Server.MapPath(testFilesDir + “candy.pdf”),
};

StreamDefinition [] streamDefinitions = filePaths.Select(path => new StreamDefinition
{
Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read),
FilenameExtension = Path.GetExtension(path)
}).ToArray();
return View(streamDefinitions);

and then in the view:
@model StreamDefinition[]
@(Html.ViewerClientCode()
.TargetElementSelector("#test2")
.Streams(Model, “candy_timesheet”)
)
@{
foreach (StreamDefinition streamDefinition in streamDefinitions)
{
streamDefinition.Stream.Dispose();
}
}

If this will not help you please share with us your beck end code of how do you create list with streams.

Thank you

The issues you have found earlier (filed as WEB-1766) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by GroupDocs Notifier.
Good day here is my code

it works with other other multiple images

SD contains a stream and an image path


List byteStreams = JsonConvert.DeserializeObject<List>(Helpers.TapeHelper.DoRequest("Document", "ws_getimagepath",
new
{
ImageNumber = imageNumber
},
Properties.Settings.Default.TapeEnvironmentCode).ToString());

this.streamDefinitions = byteStreams.Select(path => new StreamDefinition
{
Stream = new MemoryStream(path.Stream),
FilenameExtension = path.FilenameExtension

}).ToArray();

Hello Divan,


Thank you for your code example. After checking your code we can advice you next:
1. Use FileStream instead of MemoryStream
2. Ensure that you reset a stream position. Usually, when a stream is created from data or filled with new data, its position is situated on the last byte, usually at the end. And when such a stream passes to the GroupDocs.Viewer, it reads 0 bytes and reports that document is damaged and cannot be opened. Please, do not forget to reset the position by using a stream.Position = 0;
3. Mishmash with filenames, duplicate filenames. This in fact is a group of similar issues that our users experience from time to time. Some have troubles with duplicate filenames; this is described in Streams and Databases. In such cases GroupDocs.Viewer may display another document instead of the requested one. Other users try to fix such problems by generating new unique filenames every time GroupDocs.Viewer is invoked; they may use, for example, the Guid.NewGuid() method as a value in the fileName parameter. In such cases GroupDocs.Viewer works properly, but a new cache is generated on every call while the old cache cannot be used (GroupDocs.Viewer “thinks” that it displays a completely different document on every call) and also cannot be removed. As a result, the “temp” folder accumulates tons of waste which cannot be used and its size blows up very rapidly. That’s why you need to understand how caching works (see Streams and Cache).
4. Invalid filename characters. Please don’t forget that NTFS file system allows only a narrow set of available characters which can be used in the filenames.

For more info about using stream for the Viewer please check this documentation.

Best regards.

Hallo


I have changed the code to the following

List byteStreams = JsonConvert.DeserializeObject<List>(Helpers.TapeHelper.DoRequest(“Document”, “ws_getimagepath”,
new
{
ImageNumber = imageNumber
},
Properties.Settings.Default.TapeEnvironmentCode).ToString());


this.streamDefinitions = byteStreams.Select(path => new StreamDefinition
{
Stream = new MemoryStream(path.Stream),
FilenameExtension = path.FilenameExtension

}).ToArray();


foreach(StreamDefinition s in streamDefinitions)
{
s.Stream.Position = 0;
}


this is the error I am getting now

[ArgumentNullException: Value cannot be null.
Parameter name: path2]
System.IO.Path.Combine(String path1, String path2) +10646497
Groupdocs.Web.UI.Helper.SaveStreamToFile(Stream stream, String streamFileName, String fileExtension, IFileStorage sourceFileStorage, String downloadPath, Boolean useCachedStreamContentsIfPossible, Func`1 streamCreator, String targetElementSelector) +738
Groupdocs.Web.UI.ClientHelperBase.ToString() +2404
System.Web.HttpWriter.Write(Object obj) +24
System.Web.UI.HtmlTextWriter.Write(Object value) +31
ASP.default_aspx.__RenderBodyContent(HtmlTextWriter __w, Control parameterContainer) in c:\Users\du5002\Downloads\fixedProjects\FixedImageviewer\Imageviewer\ImageViewer\Default.aspx:35
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +268
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +216
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1386

Hello Divan,


In the previous thread you faced with the similar issue and you said that you fixed it. So we need to know: a project that you use is the same? you are faced with the same problem again? file that you are viewing is the same?

If the project is same which changes you made in it?

Thank you.

Good Day


It is not the same issue the previous issues have been resolved this is an different issue.

I am trying to view a array of streamdefinitions that contain 18 jpeg images

I have reset the positions of all the streams to 0 and I can see that everything looks fine in the list

I can see the bytes and that all the positions are reset to 0 of each stream.

this is where it brakes and i get the error of my previous posts

Viewer.ClientCode()
.TargetElementSelector("#MainViewerWindow")
.Streams(this.streamDefinitions,this.DownloadFileName)
.OpenThumbnails(false)
.SupportPageRotation(true)
.ShowFolderBrowser(false)
.PreloadPagesCount(1)
.ZoomToFitHeight()

This is the code I use I get a returned list of objects i cannot use file stream .

This is the object

public class SD
{
public string FilenameExtension { get; set; }
public byte[] Stream { get; set; }
}


I then use the following code


List byteStreams = JsonConvert.DeserializeObject<List>(Helpers.TapeHelper.DoRequest(“Document”, “ws_getimagepath”,
new
{
ImageNumber = imageNumber
},
Properties.Settings.Default.TapeEnvironmentCode).ToString());


this.streamDefinitions = byteStreams.Select(path => new StreamDefinition
{
Stream = new MemoryStream(path.Stream),
FilenameExtension = path.FilenameExtension

}).ToArray();

foreach(StreamDefinition s in streamDefinitions)
{
s.Stream.Position = 0;
}















I have changed my code to your example

string[] filePaths =
{

@“C:\ViewerStorage\Photo1.jpg”,
// @“C:\ViewerStorage\Photo2.jpg”,
// @“C:\ViewerStorage\Photo3.jpg”,
//@“C:\ViewerStorage\Photo4.jpg”,
// @“C:\ViewerStorage\Photo5.jpg”,
// @“C:\ViewerStorage\Photo6.jpg”,
// @“C:\ViewerStorage\Photo7.jpg”,
// @“C:\ViewerStorage\Photo8.jpg”,
// @“C:\ViewerStorage\Photo9.jpg”,
// @“C:\ViewerStorage\Photo10.jpg”,
// @“C:\ViewerStorage\Photo11.jpg”,
// @“C:\ViewerStorage\Photo12.jpg”,
// @“C:\ViewerStorage\Photo13.jpg”,
//@“C:\ViewerStorage\Photo14.jpg”,
// @“C:\ViewerStorage\Photo15.jpg”,
// @“C:\ViewerStorage\Photo16.jpg”,
// @“C:\ViewerStorage\Photo17.jpg”,
// @“C:\ViewerStorage\Photo18.jpg”,
};
this.streamDefinitions = filePaths.Select(path => new StreamDefinition
{
Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read),
FilenameExtension = Path.GetExtension(path)
}).ToArray();
But i still get the below error

Please help me

[ArgumentNullException: Value cannot be null.
Parameter name: path2]
System.IO.Path.Combine(String path1, String path2) +10646497
Groupdocs.Web.UI.Helper.SaveStreamToFile(Stream stream, String streamFileName, String fileExtension, IFileStorage sourceFileStorage, String downloadPath, Boolean useCachedStreamContentsIfPossible, Func`1 streamCreator, String targetElementSelector) +739
Groupdocs.Web.UI.ClientHelperBase.ToString() +2404
System.IO.TextWriter.Write(Object value) +80
System.Web.UI.HtmlTextWriter.Write(Object value) +31
ASP.default_aspx.__RenderBodyContent(HtmlTextWriter __w, Control parameterContainer) in c:\Users\du5002\Downloads\fixedProjects\FixedImageviewer\Imageviewer\ImageViewer\Default.aspx:35
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +268
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +102
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1386

Hello Divan,


Thank you for the example and SD class explanation. We will investigate this issue and come back to you with the updates.

Sorry for the inconvenience.

I have downgraded to 2.8 now it is working

Ok I have tried 2.13 and it also doesnt work 2.8 works but only locally.


Please keep me updated as this is critical to our bussiness. And we need it to be fixed.

Kind regards
Divan

Hello Divan,


We have resolved this issue. But unfortunately this fix will be released in the next version (2.14). Sorry but currently we can’t share the release date. We will keep you updated with all news.

Sorry for the inconvenience.