0

I am trying to download file from SharePoint using below code

url ='https://site_url/_api/web/GetFileByServerRelativeUrl("/PraveenTest/Test/file_name")/$value'
headers = {Authorization: "Bearer"  + accessToken}
response = requests.get(url=url, headers=headers)

response is 400.

Why exactly I am facing this issue?

  • Can you please post the complete code you are using? Also, check the relative path you provided is correct or not? – Ganesh Sanap Aug 13 '19 at 10:23
0

Below is the complete example of how to get the file from SharePoint:

var hostweburl = decodeURIComponent(getParameterByName('SPHostUrl'));
var appweburl = decodeURIComponent(getParameterByName('SPAppWebUrl'));

var fileContentUrl = "_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('/site/library/madcow.xlsx')/$value?@target='" + hostweburl + "'";

var executor = new SP.RequestExecutor(appweburl);
var info = {
    url: fileContentUrl,
    method: "GET",
    binaryStringResponseBody: true,
    success: function (data) {
        //binary data available in data.body
        var result = data.body;
    },
    error: function (err) {
        alert(JSON.stringify(err));
    }
};
executor.executeAsync(info);

Source: How to copy files between sites using JavaScript REST in Office365 / SharePoint 2013.

You can also check below documentation for Complete basic operations using SharePoint REST endpoints:

Complete basic operations using SharePoint REST endpoints.

| improve this answer | |
0

There is also this method.

https://siteurl/_api/web/GetFolderByServerRelativeUrl('List or Library Name/')/Files('File Name')/

The following example shows how to retrieve a file.

https://my365.onmicrosoft.com/sites/sample/_api/web/GetFolderByServerRelativeUrl('SiteAssets/')/Files('01.jpg')/
| 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.