0

I need to download a file from a sharepoint list using the rest api, the endpoint I use is the following:

https://mysite.sharepoint.com/sites/testsite/_api/web/GetFolderByServerRelativeUrl('/sites/testsit**strong text**e/SiteAssets/Lists/411sec72-5b2d-2014-n8fx5-qt1b9b5a4blp')/files('profile.png')/$value

returns Gibberish strange encodingenter image description here

3 Answers 3

0

You are most likely just looking at a png file as raw text. Try saving what you got as a png and open with photos app. enter image description here

I saved your screenshot as a png and opened it on my computer in vim.

2
  • thanks for the comment, is there a way to download the file (png, jpeg, pdf, docx) without adding the file extension manually? Commented Oct 26, 2022 at 21:25
  • You should probably find the user name of the profile.png and name them something like $user+'.png' Commented Oct 27, 2022 at 1:31
0

Looks like the SharePoint rest api doesn't provide the image/png content type header in the response, so Postman doesn't realize that the data there is a png file.

You should be able to save the data to a local file though, giving it the correct name/extension.

enter image description here

Whatever code you end up using to call the rest api and save the file should be able to write the image to a file with the appropriate name.

1
  • Thanks for answering, this works if I save the document with the correct extension Commented Oct 28, 2022 at 16:24
0

You can download the documents using below endpoint. One drawback is that this works only for PDF documents and Images.

https://mysite.sharepoint.com/sites/namesite/_layouts/15/download.aspx?SourceUrl={ServerRelativeUrl}

You can get the ServerRelativeUrl by making a call to the document library endpoint or the attachment of your list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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