Improved File Support
A question was asked in issue 214 around the best way to read and write the contents of files. After reviewing the current state we updated the library to provide better explicit support for both actions. For reading files we have introduced three new methods on the File object: getText, getBlob, and getBuffer. These return the file as a string, Blob, or ArrayBuffer - though important to remember that Blob won't work in node.js as discussed in this thread, for those cases use getBuffer if you need to work with a binary file in node. We also added better support for writing the contents of a file with setContent, which will take a string, Blob, or ArrayBuffer as the new content. We also wanted to support large file uploads so have added addChunked to the Files collection and setContentChunked to the File object. Both use the start, continue, and finish upload REST methods under the hood - but wrapped so you don't have to worry about the implementation. Below we show how to use each of these new methods:
We did when making this change remove the openBinaryStream, value, and saveBinaryStream methods from the File class in favor of the more explicit approach outlined above.
Failed HTTP Request Logging
Now failures of any HTTP requests are logged to the Logger with LogLevel.Error to make it easier to determine why calls are failing. You can use the ConsoleListener to easily write to the console - or any of the other available listeners as well as writing your own.
Because this list does not exist the request will fail, and we can now see clearly why by looking at the console output written by the Logger:
Search Suggest API Support
Based on a suggestion [pause for laughter] we added support for the search suggest API which you can now access off the root pnp.sp path. This new method takes either a string or a plain object of options and returns the results from the suggest API.
Improved Batch Scoping
Addressed an issue reported with batches that prevented execution when a Web or Site instance was created explicitly. You can now successfully create batches on a per instance basis as shown below:
Thanks to folks in the community for reporting bugs we have included fixes for those reported issues in this release:
- Fixed an issue when using node authentication with client secrets with certain special characters.
- Fixed an issue where results were undefined when using paging with items and odata=verbose.
- Fixed an issue where the expiration date wasn't being passed along in the caching wrapper's getOrPut method.
- Fixed an issue where Refiners were not working as expected with search.
- Fixed a bug that prevented the promise returned from batch.execute to resolve when a batch had internal dependencies (adding or updating a list item). Also restructured how the results are aggregated into a promise chain and returned to ensure batch.execute's promise resolved AFTER all of the batch promises.
You can download the source code of the samples shown above to try them out and easily copy the code to your own projects.
What is the JS Core Component?
“Sharing is Caring”