Store file in a local drive folder using electron or node.js - node.js

I create one software in electron. I need to add image upload functionality into it. Uploaded images will store in a local drive(D:// Drive) folder and also on preview time I need to access the same folder so I have not idea it is possible in electron and if yes then how can I do this?
And for an extra thing in the backend, I use nodejs if you have an idea about that thing is possible using node js then also tell me so I can integrate with node js also. just I need to store that images to a particular folder which is in my local drive and I also access that image from my local drive for preview things.

For selecting file to upload trigger event (ex. upload-start) through ipc from render process.
In main process in handler for this event use dialog module and .showOpenDialog() method which will return a path to the file.
Then in main process you can use fs module to work with file: read it, copy, move, rename and write.
And check How do I handle local file uploads in electron?

Related

How to setup file upload from NodeJS/VueJS to another server?

I've created a VueJS App for file uploading in which it will be my admin panel (For CMS) with NodeJS as back-end. Now I want to upload the files that was passed to the NodeJS and move it to another VueJS App which is going to be my primary website in order for me to access the files locally. How can I do it? Any suggestions or different approach will do.
You have many options on how to move the files to another site.
You could store them in a shared bucket or shared directory between your 2 backends or you could add another route to download that file.
You could configure a cronjob to scp or rsync those files to your target machine.
This is really more of a question of how to sync a directory to some place else.

Electron: Share Files Between Different O.S Packages

I've created an Electron app and build packages for Windows and MacOS using electron-packager. The app data is stored in a JSON file inside the resources folder and i'm using fs to perform file I/O tasks in the app.
What i would like to do is store the JSON file in a folder that could be accessed by both packages (Win and Mac). This way my client could use both versions of the app and the data source will be the same, thus, the data always updated.
Since i'm a Electron newbie, is there a way to "merge" both packages and share the same data file?
Thanks to #kevingelion and #revln9 from the Slack Electron discussion, i was able to solve my issue.
All i need to use is getAppPath() and from there go to the parent folder where the data file is located:
var app = require('electron').remote.app;
resourcePath = path.join(app.getAppPath(), '../../../db/'); //shared folder

Need help in developing a custom WebDav client using node.js

I am developing an open source application which should mount webdav share to local drive letter just like NETDRIVE and WEBDRIVE using node.js and electron-js, so in my application at present I am downloading all files from webdav share which takes a lot of time and not reliable for heavy data. Is there any other approach so that whenever user access a file, only that particular file should be fetched from webdav share, I’ve tried to display files meta data(dummy) structure in directory and kept that directory under file-watcher. So that when user tries to open a file then watcher should capture file open event to get which file was user trying to access, so that in background of application a service will triggered to fetch that particular file using file-path as reference, but none of them are unable to capture file open event. Is there any other approach to do so, correct me if I am in wrong direction.
Thank's
I think you want virtual file-system and recommend Dokan library.
Dokan is the start point of Windows virtual file-system application.
Open Source : Dokan (https://en.wikipedia.org/wiki/Dokan_Library)
Commercial: EldoS CBFS (https://www.eldos.com/cbfs)
Google, Naver use Dokan and NetDrive, RaiDrive(mine) use CBFS.

Possible to set local folder for automatic file uploads

Bit of a loose question so if it gets marked down I'll remove it.. but..
I'm using Primefaces/Spring/Hibernate for Java server.
My application knows a load of file names I need to upload. Those files are on my local computer. Is it possible to tell the application the root directory of these files, for it to then setup uploads for each of these files without me needing to browse for each file individually?
I assume this is a browser security issue, i.e. the user needs to explicitly state which file the application is allowed to know about etc?
If not I'll have to do it in a local application but I was hoping there was a way a mass upload could be kicked off from the browser by just setting the local directory of the files.
I decided to use the Primefaces uploader, upload all the files in the directory and let the application sort them out once it has them on the server.

Node Webkit Desktop App - Browser default caching of PDF files

I have built a desktop app using node webkit and need to cache PDF files that are viewed via the App when online so that they are also available offline. I haven't found a solution yet but during testing I noticed that files that I had previously viewed online were available offline even though I haven't written any code for this yet. Therefore these must already be cached automatically. I did a search to find where the files are being saved exactly but couldn't find anything.
Can anyone explain this or point me in the direction of information on this so that I understand how it works and ensure my App can utilise the default behaviour of the browser caching?
********UPDATE***********
I have found a solution to store the PDFs locally, however this isn't my query. I am looking for an explanation as to HOW the PDFs are available when offline without this code I have written. The files must be automatically be stored somewhere otherwise how would they display?
The default caching behavior of node-webkit is controlled by the page-cache property in package.json :
"webkit": {
"page-cache": true
},
Only typical web resources can be cached this way (scripts, style sheets, etc.). To be able to view PDF files offline, you can store them manually.
There are several ways to do that :
Save a file directly to disk (the simple solution, just store the files in App.dataPath)
Use a database
Use Web Storage
Use the application cache
All of these are documented here : Save persistent data in app
The default location to cache your app files is mentioned in your package.json manifest file.When the app is initialized the settings in your manifest files are loaded by default.Since cached files cannot be accessed programmatically,you can overwrite the default files manually.
To get the application’s data path in user’s directory for windows,you can write it in Jason format in your package :
Windows: %LOCALAPPDATA%/
You can read about other cache menthods in node webkit's documentation :
http://docs.nwjs.io/en/latest/References/App/#appclearcache

Resources