web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How get base64 string from the application/octet-stream using CRM Plugin or javascript?

(0) ShareShare
ReportReport
Posted on by

Hi,

I have to read file(pdf) from sharepoint and In REST API response I am getting data with  of type application/octet-stream I need to create file stream and create file(pdf).

Thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    This might be something else to look at, but maybe an options:

               string contentType = System.Web.MimeMapping.GetMimeMapping(fileName);

               HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

               Byte[] bytes = downloadFile(item);

               response.Content = new ByteArrayContent(bytes);

               response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");

               response.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);

               response.Content.Headers.ContentDisposition.FileName = fileName;

    The download file function looks like this. This was implemented for SharePoint, so you would have to modify accordingly to your requirements.

           public static byte[] DownloadFile(ListItem item)

           {

               ClientContext ctx = ConnectToSharePoint();

               List spList = ctx.Web.Lists.GetByTitle("Documents");

               ctx.Load(spList);

               ctx.ExecuteQuery();

               ClientResult<System.IO.Stream> result = item.File.OpenBinaryStream();

               ctx.ExecuteQuery();

               using (System.IO.MemoryStream ms = new System.IO.MemoryStream())

               {

                   result.Value.CopyTo(ms);

                   return ms.ToArray();

               }

           }

  • Community Member Profile Picture
    on at

    I have checked for same but, ClientContext way throwing permission exceptions for sharepoint online credential object.

    Some others developers are also not suggesting this way as it's not supported on sand box.

    Please share other options..

    Thanks for quick response!

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    I had the API hosted on Azure, which is why I didn't have the issue with Sandboxed environment, and restricted only for CORS to the CRM server. Not sure if this is an option for you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans