Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

can not upload file to Sharepoint with API

$
0
0
Hi,

I have problem to upload file to sharepoint with API. What is strange here - no problems with download file.

In general i have the following permission for Add-in Access

<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read" />
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Write" />
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Manage" />
</AppPermissionRequests>

I do not expect issue with token generation as downloading file is working.

According to https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest
i am using request as below

url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/add(url='a.txt',overwrite=true)
method: POST
body: "Contents of file"
Headers:
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    

    
    
Because I ma using python for that, my requests looks like below

###################################################################
r = requests.post(api_url, headers=headers, data=file_body)
headers={'Accept': 'application/json;odata=verbose', 'Authorization': 'Bearer eyJ.......7A', 'X-RequestDigest': '0x31...BAE,14 Nov 2018 15:11:22 -0000'}
api_url = "https://..../sites/XYZ/_api/web/GetFolderByServerRelativeUrl('%2Fsites%2XYZ%2My%20Documents')/Files/add(url='doc.txt',overwrite=true)"
###################################################################

as a result I got HTTP403
{"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}

Do You have any idea what is happening here and how to resolve it?

thanks in advance,
BR,
Grzegorz

Viewing all articles
Browse latest Browse all 7589

Trending Articles



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