I'm doing a REST request to get file contents from a file in my SharePoint library. So far, I've managed to get the actual contents from any file I need, and I've tried converting to binary. But, for example, if I try to pull information from a Word document, it comes out something like this:

üÜé×·Äxj¨ADtÙ$Kq"´¹æ7!v9gaL·;p¯ÀÄÄ .B"Sí¯þ´è|Û 3ÐÑÑ _Xä k

It works fine on .txt files, but I'm trying to do it from a .onepkg, so what can I do to convert this data into readable content?


I'm not completely sure if this will help you but Here is a sample of code that I use to pull a pdf file into the browsers memory so I can then use another rest request to upload the file to Adobe Echosign.

If you know the file's url or if you have done a Get on the library via the document ID I would use the FieldValuesAsText.FileRef for the server relative url to the file.

My page has a config object that stores everything so when you see config.blob = this.response that's just how I'm storing the data.

    function GetFileContents(){
    var RequestURL = "YourFileURLHERE"
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function(){
        if(this.readyState == 4 && this.status ==200){
            console.log(this.response, typeof this.response);
            //Your variable where you want to hold the data
            config.blob = this.response;
    xhr.open('GET', RequestURL, true);
    xhr.responseType = 'blob';

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.