'How to convert local image path to url

I am fairly new to React, and is trying to convert an local image file path to a data url or blob url that can be used in the src.

import image from "./img1.jpeg" will not work for my case because the image file will only be created after some user interaction that will trigger the backend processing script.

I have an idea of creating a hidden upload field and upload the image then convert it to URL with URL.createObjectURL(e.target.files[0]) but I have no knowledge in doing that...

Since @quentin stated that I should convert the file path to URL in server-side code(expressjs), how can I do the conversion?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source