My requirement is that there is a file called abc.pdf in a document library. Depending upon the logged in user and today's date, the downloaded file's name is to be changed. For example, if last name of the logged in user is Karthik, then the name of the downloaded file must be abc_Karthik_13-01-17.pdf.

So, I am trying to complete the requirement by getting content of the file in a JavaScript variable and download it using msSaveOrOpenBlob method. Below are relevant code snippets:

    type: 'GET',
    url: "/_api/web/getfilebyserverrelativeurl('<relative url>')/openbinarystream",
    binaryStringResponseBody: true,
    success: function (data) {
        var blobData = data;
        var blobObject = new Blob([blobData]);
        window.navigator.msSaveOrOpenBlob(blobObject, 'abc_Karthik_13-01-17.pdf')
    error: function (error) {

The strange issue that I am facing is that I am not getting the complete contents of the pdf file in the data variable. But when I see fiddler trace, I am able to see the full contents in the body. Below is the screenshot of fiddler for that ajax request. You can see that the vertical scroll bar is so big. My question is : Why am I not getting the complete contents of the file in the data variable but I can see the complete content in fiddler trace ?

enter image description here

  • try /_api/web/getfilebyserverrelativeurl('<relative url>')/$value – sekhar Jan 13 '17 at 11:01
  • @sekhar thanks for the comment but I already tried it and it is not working. I am facing same issue with $value – Karthik Jan 13 '17 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.