How to allow other machines to download from our Electron app?


#1

Hi everyone,

The question is weird but it’s because I don’t even have any knowledge about this concept.

Here is the thing:
I’m working with an Electron app that is a white board application.

User can draw something onto the board and export it to PDF.

This PDF will be saved into a folder (I assume AppData folder on Windows or something like that on MacOS), so that other machines can access (download) it.

Now I don’t know how to allow other machines to download this file.

Normally we will need to share the folder (on Windows), and other machines can go to Networks/our-machine to find and download the shared files.

But the owner of this app said that we can download it if both machines are on the same LAN, using some kind of URL like 192.168.x.x:6554/mypdfile_somerandomid.pdf

I don’t know how is this possible. Can you please suggest some solutions?

Thank you very much


#2

Since Electron is Node, you can run a simple Express server on some port which you can link to along with the user’s public IP address.

Maybe something like,

const electron = require('electron')
const express = require('express')
const path = require('path')
const app = express()

const UPLOAD_PATH = path.join(electron.app.getPath('appData'), 'uploads')

app.use(express.static(UPLOAD_PATH))
app.listen(6554, 'localhost')

But, I would recommend not doing that unless the user is 100% aware that you are sharing their IP address, and even then the links may break if their IP changes. It would be a better idea to store these files on something like Amazon S3 using a random UUID as a filename, and link to it that way.