Home Web Front-end JS Tutorial In Tauri Vue3 application: How to correctly parse local binary image files?

In Tauri Vue3 application: How to correctly parse local binary image files?

Apr 04, 2025 am 11:27 AM
vue Browser tool ai

In Tauri Vue3 application: How to correctly parse local binary image files?

Solutions to parse local binary image files in Tauri and Vue3 applications

This article discusses the problem that local images cannot be displayed due to security policy restrictions in the Markdown parser built with Tauri, Vue3, and markdown-it, and provides a final solution.

Problem: This tool uses v-html to render images (relative paths) in a Markdown file. The image is displayed normally in development mode, but after construction, the browser security policy still prevents the front-end from accessing local images even if the path is converted to an absolute path (for example: https://tauri.localhost/img/xxx.png ).

Try: Modifying the CSP policy in tauri.conf.json (for example, setting img-src to * ) is invalid. Two solutions were tried: 1. Use Tauri's fs API to read local files; 2. Read binary files in the Rust backend, pass data to the frontend, and parse using Blob object. Both solutions cause the image display to be corrupt or unloadable. The suspect is the image parsing or data format of Vue.js.

The initial front-end code tries to convert the binary data into a string, then encodes it as base64 using window.btoa , and finally sets src attribute of img element.

Final solution: Generate URL using Blob object and URL.createObjectURL method. The code is as follows:

 let img_path = "E:/myProjects2/tauri_vue/mdren/img/a-1-01.png";
const contents = await readBinaryFile(img_path); // Assume that the readBinaryFile function has been defined let blob = new Blob([contents], { type: "image/png" });

async function reloadImg() {
  let img_element = document.querySelectorAll("#img-to-remove");
  img_element.forEach(async (element) => {
    element.src = URL.createObjectURL(blob);
  });
}
Copy after login

Cause analysis: The previous solution failed may be due to CSP configuration errors or Rust backend data delivery issues. Use the Blob object and URL.createObjectURL to directly create the image URL, bypassing security policy restrictions and successfully resolve the image display problem.

The above is the detailed content of In Tauri Vue3 application: How to correctly parse local binary image files?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
How reliable is Binance Plaza? How reliable is Binance Plaza? May 07, 2025 pm 07:18 PM

Binance Square is a social media platform provided by Binance Exchange, aiming to provide users with a space to communicate and share information related to cryptocurrencies. This article will explore the functions, reliability and user experience of Binance Plaza in detail to help you better understand this platform.

The latest download tutorial for Ouyi OKX6.118.0 version The latest download tutorial for Ouyi OKX6.118.0 version May 07, 2025 pm 06:51 PM

The latest download tutorial for Ouyi OKX6.118.0 version: 1. Click on the quick link in the article; 2. Click on the download (if you are a web user, please register the information first). The latest Android version v6.118.0 optimizes some functions and experiences to make trading easier. Update the app now to experience a more extreme trading experience.

2025 Binance Binance Exchange Latest Login Portal 2025 Binance Binance Exchange Latest Login Portal May 07, 2025 pm 07:03 PM

As the world's leading cryptocurrency exchange, Binance is always committed to providing users with a safe and convenient trading experience. Over time, Binance has continuously optimized its platform features and user interface to meet the changing needs of users. In 2025, Binance launched a new login portal aimed at further improving the user experience.

2025 Binance Online Web Address 2025 Binance Online Web Address May 07, 2025 pm 06:54 PM

As the world's leading cryptocurrency exchange, Binance is always committed to providing users with a safe and convenient trading experience. Over time, Binance has continuously optimized its platform features and user interface to meet the changing needs of users. In 2025, Binance launched a new login portal aimed at further improving the user experience.

2025 Binance latest address 2025 Binance latest address May 07, 2025 pm 06:57 PM

As the world's leading cryptocurrency exchange, Binance is always committed to providing users with a safe and convenient trading experience. Over time, Binance has continuously optimized its platform features and user interface to meet the changing needs of users. In 2025, Binance launched a new login portal aimed at further improving the user experience.

How to save Binance's liquidation How to save Binance's liquidation May 07, 2025 pm 07:09 PM

In cryptocurrency trading, liquidation is a common but headache. Especially when using large trading platforms like Binance, users may face the risk of losing their positions due to violent market fluctuations. This article will discuss in detail how to save Binance after the liquidation of the stock, as well as some preventive measures.

Download the latest version of Ouyi OKX5.1 Download the latest version of Ouyi OKX5.1 May 07, 2025 pm 06:48 PM

The latest download tutorial for Ouyi OKX6.118.0 version: 1. Click on the quick link in the article; 2. Click on the download (if you are a web user, please register the information first). The latest Android version v6.118.0 optimizes some functions and experiences to make trading easier. Update the app now to experience a more extreme trading experience.

10 latest tools for web developers 10 latest tools for web developers May 07, 2025 pm 04:48 PM

Web development design is a promising career field. However, this industry also faces many challenges. As more businesses and brands turn to the online marketplace, web developers have the opportunity to demonstrate their skills and succeed in their careers. However, as demand for web development continues to grow, the number of developers is also increasing, resulting in increasingly fierce competition. But it’s exciting that if you have the talent and will, you can always find new ways to create unique designs and ideas. As a web developer, you may need to keep looking for new tools and resources. These new tools and resources not only make your job more convenient, but also improve the quality of your work, thus helping you win more business and customers. The trends of web development are constantly changing.

See all articles