diff --git a/README.md b/README.md index 1f25e65a..2f20897a 100644 --- a/README.md +++ b/README.md @@ -555,7 +555,7 @@ Files may be uploaded to the WordPress media library by creating a media record The file to upload can be specified as - a `String` describing an image file path, _e.g._ `'/path/to/the/image.jpg'` -- a `Buffer` with file content, _e.g._ `new Buffer()` +- a `Buffer` with file content, _e.g._ `Buffer.from()` (or the result of a `readFile` call) - a file object from a `` element, _e.g._ `document.getElementById( 'file-input' ).files[0]` The file is passed into the `.file()` method: @@ -564,7 +564,7 @@ The file is passed into the `.file()` method: wp.media().file(content [, name])... ``` -The optional second string argument specifies the file name to use for the uploaded media. If the name argument is omitted `file()` will try to infer a filename from the provided content. +The optional second string argument specifies the file name to use for the uploaded media. If the name argument is omitted `file()` will try to infer a filename from the provided file path. Note that when uploading a Buffer object `name` is a required argument, because no name can be automatically inferred from the buffer. #### Adding Media to a Post diff --git a/lib/constructors/wp-request.js b/lib/constructors/wp-request.js index d5d9cd0b..78eaeda4 100644 --- a/lib/constructors/wp-request.js +++ b/lib/constructors/wp-request.js @@ -633,6 +633,11 @@ WPRequest.prototype.auth = function( credentials ) { * .file( '/path/to/file.jpg' ) * .create({})... * + * wp.media() + * // Pass .file() an image as a Buffer object, and a filename string + * .file( imgBuffer, 'desired-title.jpg' ) + * .create({})... + * * @example