0

I have a site on SharePoint Online with some documents in the Shared Documents document library I'd like to download via REST. All the calls I make are returning a bunch of file properties in XML. I can't seem to get the binary file contents. For example:

https://mycompany.sharepoint.com/sites/MySite/_api/web/GetFolderByServerRelativeUrl(
    '/sites/MySite/Shared Documents')/Files('MyDocument.docx')

Returns a big XML document including:

<m:properties>
  <d:CheckInComment/>
  <d:CheckOutType m:type="Edm.Int32">2</d:CheckOutType>
  <d:ContentTag>{2b9067cd-cb9b-4643-a9d6-19ef489b33e4},1,2</d:ContentTag>
  <d:CustomizedPageStatus m:type="Edm.Int32">0</d:CustomizedPageStatus>
  <d:ETag>&quot;{2b9067cd-cb9b-4643-a9d6-19ef489b33e4},1&quot;</d:ETag>
  <d:Exists m:type="Edm.Boolean">true</d:Exists>
  <d:IrmEnabled m:type="Edm.Boolean">false</d:IrmEnabled>
  <d:Length m:type="Edm.Int64">19900</d:Length>
  <d:Level m:type="Edm.Byte">1</d:Level>
  <d:LinkingUri>https://mycompany.sharepoint.com/sites/MySite/Shared%20Documents/MyDocument.docx?d=w2b9068bccb9b4643a9d619ef489b33e3</d:LinkingUri>
  <d:LinkingUrl>https://mycompany.sharepoint.com/sites/MySite/Shared Documents/MyDocument.docx?d=w2b9068bccb9b4643a9d619ef489b33e3</d:LinkingUrl>
  <d:MajorVersion m:type="Edm.Int32">1</d:MajorVersion>
  <d:MinorVersion m:type="Edm.Int32">0</d:MinorVersion>
  <d:Name>MyDocument.docx</d:Name>
  <d:ServerRelativeUrl>/sites/MySite/Shared Documents/MyDocument.docx</d:ServerRelativeUrl>
  <d:TimeCreated m:type="Edm.DateTime">2020-05-07T20:38:53Z</d:TimeCreated>
  <d:TimeLastModified m:type="Edm.DateTime">2020-05-07T20:38:53Z</d:TimeLastModified>
  <d:Title/>
  <d:UIVersion m:type="Edm.Int32">512</d:UIVersion>
  <d:UIVersionLabel>1.0</d:UIVersionLabel>
  <d:UniqueId m:type="Edm.Guid">2b9067cd-cb9b-4643-a9d6-19ef489b33e4</d:UniqueId>
</m:properties>

From what I've seen elsewhere, adding /$value to the end of the URL should return the file contents, but it just returns the same XML.

0

Below endpoint is for file downloading.

https://abc.sharepoint.com/sites/s01/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/s01/Shared%20Documents/file-example_PDF_500_kB.pdf')/$value

You can take a reference of the API doc:

BR

| improve this answer | |
0

Yeah, I've found that:

https://mycompany.sharepoint.com/sites/MySite/_api/web/GetFileByServerRelativeUrl('/sites/MySite/Shared%20Documents/MyDocument.docx')/$value

Also, only returns the XML metadata for the file and not the actual file. That or a 404 error for platform independent clients that may not be able to process both the content and the metadata from the one response.

I've found that:

https://mycompany.sharepoint.com/sites/MySite/_api/web/GetFileByServerRelativeUrl('/sites/MySite/Shared%20Documents/MyDocument.docx')/OpenBinaryStream()

Actually returns the file.

Reference:

https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-csom/jj170439(v=office.15)

| improve this answer | |
0

It was a silly mistake. The /$value suffix works, I just wasn't escaping the $ with a backslash on the (Linux) command line.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.