July 2017
Intermediate to advanced
300 pages
5h 43m
English
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( ...Read now
Unlock full access