0

Hi

I have a requirement in a SharePoint Hosted App to upload file to SharePoint Documents Library but the request to upload file is getting failed with following error:

============================
Status Code:
——————-
403 Forbidden
============================

============================
Response
——————-
{“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.”}}}
============================

============================
Response Header:
——————-
X-Forms_Based_Auth_Required :::: https://myurl.sharepoint.com/_forms/default.aspx?ReturnUrl=/_layouts/15/error.aspx&Source=%2f_vti_bin%2fclient.svc%2fSP.AppContextSite(%40target)%2fweb%2flists%2fgetByTitle(%27Shared%2520Documents%27)%2fRootFolder%2fFiles%2fAdd(url%3d%27a.dat%27%2c%2520overwrite%3dtrue)%3f%40target%3d%2527https%3a%2f%2fmyurl.sharepoint.com%2fsites%2fmysite%2527

X-MSDAVEXT_Error :::: 917656; Access+denied.+Before+opening+files+in+this+location%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically.

The app has following permission:

Tenant: Full control
List: Full Control
Web: Full control
Site Collection: Full control

I am using following code to upload the file:

$.getScript(
hostweburl + “/_layouts/15/SP.RequestExecutor.js”,
function () {var ro = new SP.RequestExecutor(appweburl);

    var info = {
        url: appweburl + “/_api/SP.AppContextSite(@target)/web/lists/getByTitle(‘Shared Documents’)/RootFolder/Files/Add(url=’a.dat’, overwrite=true)?@target='” + hostweburl + “‘”,
        method: “POST”,
        binaryStringRequestBody: true,
        body: data,
        processData: false,
        headers: {
            “accept”: “application/json; odata=verbose”,
            “content-type”: “application/json;odata=verbose”,
            “content-length”: data.length,
            “X-RequestDigest”: $(“#__REQUESTDIGEST”).val()
        },
        success: success,
        error: errorHandler,
        state: “Update”
    };
    ro.executeAsync(info); });

Will appreciate if anyone of you could help me in resolving this issue. 

Thanks

Haroon

(Visited 79 times, 1 visits today)
Add a Comment