Quantcast
Channel: Developing Apps for SharePoint 2013 forum
Viewing all articles
Browse latest Browse all 8089

Error reading stream downloaded from Office 365 by SP Client API

$
0
0

Hi All,

I encountered an error when I try to read a stream downloaded from SharePoint online by SP Client API. This is something I used in a SharePoint Provider-Hosted App. I want to show the users' profile picture in my app and use a generic handler to handle the picture stream downloaded from SharePoint online.

The error information is as follows:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: streamId
   at Microsoft.SharePoint.Client.AttachmentStreamFromServer.get_UnderlyingStream()
   at Microsoft.SharePoint.Client.ReadonlyWrapStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at {Namespace}.ImgHandler.ProcessRequest(HttpContext context)

The problematic code is something like:

if (spFileStream.Value != null)
{
    Int32 dataRead = 0;
    Byte[] imageBuffer = new Byte[10240]; //10KB Buffer
    while ((dataRead =spFileStream.Value.Read(imageBuffer, 0, imageBuffer.Length)) > 0) //PROBLEMATIC
        context.Response.OutputStream.Write(imageBuffer, 0, dataRead);
    context.Response.End();
}

The spFileStream is downloaded by SP Client API like:

File spFile = clientContext.Web.GetFileByServerRelativeUrl(imageUri);
clientContext.Load(spFile);
ClientResult<System.IO.Stream> spFileStream = spFile.OpenBinaryStream();
clientContext.ExecuteQuery();

Any ideas? Thanks a lot.


Cavendish Feng



Viewing all articles
Browse latest Browse all 8089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>