79700488

Date: 2025-07-14 06:16:50
Score: 5
Natty: 4
Report link

Title : Tauri + React: Image not displaying after saving in AppData folder

Hello everyone,
I’m working on a project using Tauri with React, and I’ve run into an issue with image handling.

I’m creating an images folder inside the AppData directory and copying uploaded images into that folder. I also store the image path in the SQLite database. Everything works fine during upload — the image is saved correctly, and the path is stored — but when I try to display the image later in my app, it doesn’t show up.

Here’s the function I’m using to add a product and save the image:

async function addProduct( file, productName, category, price, description ) { try { const database = await initDatabase(); const tokenExists = await exists("images", { baseDir: BaseDirectory.AppData, }); if (!tokenExists) { await mkdir("images", { baseDir: BaseDirectory.AppData, }); } const filename = await basename(file); const uniqueName = `${Date.now()}${filename}`; const destinationPath = `images/${uniqueName}`; await copyFile(file, destinationPath, { toPathBaseDir: BaseDirectory.AppData, }); await database.execute( "INSERT INTO product (productImage, productName, category, price, description) VALUES (?, ?, ?, ?, ?)", [destinationPath, productName, category, price, description] ); return { ok: true, message: "Product added successfully" }; } catch (error) { console.error("❌ Failed to add product:", error.message); throw error; } }

To display the image, I’m trying to load it like this:

<img src={`C:\\Users\\YourUser\\AppData\\Roaming\\com.product.app\\images\\${item.productImage}`} />

But the image is not rendering, and the console shows an error:
"Not allowed to load local resource"

Question:

Any help would be appreciated

Reasons:
  • Blacklisted phrase (1): appreciated
  • Blacklisted phrase (1): Any help
  • RegEx Blacklisted phrase (3): Any help would be appreciated
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Mudasir Nadeem