O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Transferring graphics

It doesn't look very handy, does it? It would be more interesting if we could copy/paste a file. Unfortunately, NW.js doesn't give us many options when it comes to file exchange. However, we can transfer PNG and JPEG images between the NW.js application and external programs:

./js/Service/File.js

//...   copyImage( file, type ){     const clip = nw.Clipboard.get(),           // load file content 

as Base64           data = fs.readFileSync( file ).toString( "base64" ),           // image as HTML       

    html = `<img src="file:///${encodeURI( data.replace( /^//, "" ) )}">`;      // write both options 

(raw image and HTML) to the clipboard     clip.set([       { type, data: data, raw: true },       { type: 

"html", data: html }     ]);   }     copy( file ){  this.copiedFile = this.dir.getFile( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required