Pnpjs: File.getBuffer() error in new version 1.0.5

Created on 14 May 2018  Â·  9Comments  Â·  Source: pnp/pnpjs

### Category

  • [ ] Enhancement
  • [ x] Bug
  • [ ] Question
  • [ ] Documentation gap/issue

### Version

Please specify what version of the library you are using: [ 1.0.5 ]

After the upgrade to version 1.0.5, the following code stopped working.

sp.web.getFolderByServerRelativeUrl(this.props.projectReferencesTemplatesLibraryUrl)
      .files.getByName(option.text + ".docx").getBuffer().then((buffer : ArrayBuffer) => {
        this.content = buffer;
      });

Error:
Uncaught (in promise) TypeError: r.buffer is not a function
at BufferParser.parseImpl (pipeline.ts:27)
at parsers.ts:36
at new Promise ()
at BufferParser.ODataParserBase.parse (parsers.ts:35)
at pipeline.ts:226

code fixed bug

All 9 comments

Also this code doesn't work too:

sp.web.getFolderByServerRelativeUrl(this.props.projectReferencesTemplatesLibraryUrl)
      .files.getByName(option.text + ".docx").get().than(file => {    
         file .getBuffer().then((buffer : ArrayBuffer) => {
        this.content = buffer;
      });
});

Error: getBuffer() is not a function.
Downgrading to 1.0.4, fixed the error.

Thanks, I see what happened. Sorry about that - will get a fix in.

Error in making file request using server relative path. The request path is invalid. It is adding api after pages library instead of site

pnp.sp.web.getFileByServerRelativeUrl("https://xxxxxx/Plus/DocumentLibrary/folder1/folder2/file.pdf").getBuffer().then((buffer : ArrayBuffer) => {
this.content = buffer;
});

https://xxxxxx/Pages/gfs/_api/web/getFileByServerRelativeUrl('/DocumentLibrary/folder1/folder2/file.pdf"')/$value

Hi @ahsanranjha - this is a separate issue and shouldn't be tacked to the end of an existing thread. You haven't really provided enough details here to help, but my guess is that you need to provide the context within your SPFx webpart. Please see getting started page.

Fixed, not yet merged. Will close issue on merge. Thanks!

Fixed in 1.1.0

I have updated to 1.1.0 the pnp/sp and the pnp/common and still facing the same issue
image
image

I'm importing properly, setting context at init time and reading the item properties works, only fails the getBuffer(), my call:

sp.web.getFileByServerRelativeUrl("/sites/SiteDEV/Shared Documents/tag-example.docx").getBuffer().
                 then((buffer: ArrayBuffer) => {
                   Dialog.alert("Finally!");
                 });

any tip? am I doing anything wrong?
File exists and I can download it with REST call like this:

sp.web.getFolderByServerRelativeUrl("/sites/SiteDEV/Shared Documents/")
                .files.getByName("tag-example.docx").get().then(file => {
                        Dialog.alert("got the file");

                        if (file !== undefined && file !== null) {
                            var spRequest = new XMLHttpRequest();
                            spRequest.open('GET', file.ServerRelativeUrl, true); // last parameter states if async or sync(deprecated)
                            spRequest.setRequestHeader("Accept","application/json; odata=verbose");  
                            spRequest.setRequestHeader("Content-Type","application/json"); 
                            spRequest.responseType =  "arraybuffer";// "blob";//

                            console.log('passed through getconfiguration')
                            spRequest.onreadystatechange = function(){
                                if (spRequest.readyState === 4 && spRequest.status === 200){
                                  const blob: Blob = spRequest.response; // new Blob();
                                 //it Works 
}
}
});

That class is actually in pnp/odata. Please try updating all of the libraries and see if that gets you sorted. Please let us know so we can ensure to get this resolved. Thanks!

Thanks,

Patrick

(Sent from phone, pardon spelling errors)


From: pabmardo notifications@github.com
Sent: Tuesday, May 29, 2018 4:05:59 PM
To: pnp/pnpjs
Cc: Patrick Rodgers; State change
Subject: Re: [pnp/pnpjs] File.getBuffer() error in new version 1.0.5 (#103)

I have update to 1.1.0 the pnp/sp and the pnp/common and still facing the same issue
[image]https://user-images.githubusercontent.com/29203116/40663435-f25462ba-6358-11e8-93ad-6cdb5cd17af5.png
[image]https://user-images.githubusercontent.com/29203116/40663495-1394b024-6359-11e8-99a2-a00087d3348e.png

I'm importing properly, setting context at init time and reading the item properties works, only fails the getBuffer(), my call:
sp.web.getFileByServerRelativeUrl("/sites/SiteDEV/Shared Documents/tag-example.docx").getBuffer().
then((buffer: ArrayBuffer) => {
Dialog.alert("Finally!");
});

any tip? am I doing anything wrong?

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHubhttps://github.com/pnp/pnpjs/issues/103#issuecomment-392789282, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AMi5jhYoo0JHRc8mI8XMX3hSUVw879_Vks5t3VXHgaJpZM4T9wor.

Perfect! I've tested and its working as it should.... Then probably it was working as you suggested, with 1.0.4 but I downgraded the pnp/sp only and it failed for me too.... I ended doing the rest request. As the documentation is very little, it would help being more specific, but amazing job people!!
Kudos
Pablo

Was this page helpful?
0 / 5 - 0 ratings