1

Developing an app in electron and react, everything is working fine in development mode but in production mode, I'm getting path issue.

Windows - v 10 Electron - v1.8.9 React - v16.3

When the app opens, raising an event for downloading data from server to local system for displaying in offline mode.

In development mode with internet the file paths as below

"D:\Workspace\Electron App\images\image01.jpg"
"D:\Workspace\Electron App\images\image02.jpg"
"D:\Workspace\Electron App\images\image03.jpg"

In distribution mode without internet the file paths are like this

"C:\Program Files\Electron App\resources\app.asar\images\.eslintignore"
"C:\Program Files\Electron App\resources\app.asar\images\app"
"C:\Program Files\Electron App\resources\app.asar\images\app.js"
"C:\Program Files\Electron App\resources\app.asar\images\node_modules"

From above URL app.asar is a file not a folder, and i'm not able to find the downloaded files, and i'm not sure why the URL has .eslintignore - app - app.js

Here is my code to download files

const downloadFile = (configuration) => {
    const { remoteFile, localFile } = configuration;

    return new Promise((resolve, reject) => {
        const req = request({
            method: 'GET',
            uri: remoteFile,
        });

        const out = fs.createWriteStream(localFile);
        req.pipe(out);

        req.on('end', () => resolve());

        req.on('error', () => reject());
    });
};

ipcMain.on(STORE_DATA, (event, data) => {
    const storedPaths = [];
    const dataLength = data.length;
    const storingPath = path.join(__dirname, '/images/');

    data.map((remoteFileSource) => {
        const filename = remoteFileSource.url.split('/').pop().split('#')[0].split('?')[0];

        downloadFile({
            remoteFile: remoteFileSource.url,
            localFile: storingPath + filename,
        }).then(() => {
            const storedData = {
                url: storingPath + filename,
            };
            storedPaths.push(storedData);

            // Send paths to local files
            if (dataLength === storedPaths.length) {
                mainWindow.send(STORED_DATA, storedPaths);
            }
        });
    });
});

Looking forward for much needed help

Thank you

1 Answer 1

3

Have you tried using .getPath

This API lets you find explicitly a given path name

Sign up to request clarification or add additional context in comments.

5 Comments

thank you so much for your response, I have not tried. but I'm getting the files location in the callback from path. "C:\Program Files\Electron App\resources\app.asar\images\Image01.png"
but when i explicitly tried to get files from the above path, there is no such file.
Can you please tell me where would be the ideal place to store the file in the local system. because I tried to create a folder, windows is throwing error ERROR: EPERM, operation not permitted, mkdir
Hey thank you for the answer I figured it out, actually, i was storing the files in the wrong directory.
Happy that i could assist, take care!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.