0

I am using sprestlib to upload a file to sharepoint, for that I am getting Access to XMLHttpRequest "url" from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request. Authentication will be needed to use sharepoint endpoint. I am not sure which header to use ?

This is the code

 sprLib.rest({
        url:'sites/Documents/test',
        type:"POST",
        data:reader.result,
         headers:{
            headers:{
            "accept": "application/json;odata=verbose",
            "content-length": reader.result.byteLength,
            "X-RequestDigest":<digest value>
        }
         }
    })
    .then(function(objFile){
        console.log('SUCCESS: '+objFile.Name);
    })
    .catch(function(strErr){
        console.error(strErr);
    });
   }
tomioka
  • 1
  • 1
  • Are you familiar with CORS? If not, take the time to read https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS. Then figure out whether the resource you're requesting is configured for CORS (it likely isn't). – jub0bs Jan 30 '23 at 20:03

0 Answers0