0

I am trying to get a document from document library.I am getting the file but I can't get its binary value.

 $.ajax({
    url: fileUrl,
    binaryStringResponseBody: true,
    headers: {
        "Accept": "application/json; odata=verbose",
        "X-RequestDigest": 'digest'
    },
    type: "GET"
})
.done(Function.createDelegate(this, readFileSuccess))
.error(Function.createDelegate(this, readFileFailure));

but it didn't give me a binary value for the file. I need to get binary value and store it to local storage ( Web SQL ).

How to get the binary value?

2
  • Is FileURL direct link of file or is it a REST query? Commented Apr 14, 2015 at 16:42
  • i am using direct link
    – user36977
    Commented Apr 14, 2015 at 16:57

1 Answer 1

0

You can use success handler for reading file content

function readFileSuccess(data) {
    alert(data);
}

Update

var executor = new SP.RequestExecutor(weburl);
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);
5
  • yes i have used that but it doesnt give me a binary data
    – user36977
    Commented Apr 14, 2015 at 16:48
  • You should use SP.RequestExecutor to read in binary format. Take a look at this link techmikael.blogspot.no/2013/07/… Commented Apr 14, 2015 at 16:51
  • its also give me same result
    – user36977
    Commented Apr 14, 2015 at 16:56
  • You can convert it to binary using jsfiddle.net/bdgNZ/2 Commented Apr 14, 2015 at 17:07
  • both binary are different.. if i convert that data to binary and if i get binary value from server side code. document is corrupted after converting that
    – user36977
    Commented Apr 14, 2015 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.