I have been trying to load a png image using Pixi.js in a Vite/React frontend & Golang backend. I have been stuck with the following error:
“[Assets] <MyAssetURL> could not be loaded as we don’t know how to parse it, ensure the correct parser has been added”
The method attempting to retrieve the image is the following simple code:
async function getCanvas() {
// Get the latest image from the server
Assets.load({
src: '/api/getcanvas',
loader: 'loadTextures'
})
.then((canvas_texture) => {
console.log(canvas_texture); // This console.log prints 'null'
// Create a new sprite from the image
const sprite = Sprite.from(canvas_texture);
// Clear the canvas and add the new image
appRef.current.stage.removeChildren();
appRef.current.stage.addChild(sprite);
})
}
And the Golang backend serves the file like so:
func Handler_getcanvas(w http.ResponseWriter, r *http.Request) {
// Get the latest canvas data
canvas_path, _ := backup.GetLatestBackup("../data/full_sized")
fmt.Println(canvas_path)
canvas_img, _ := os.Open(canvas_path)
// Prepare the response
w.Header().Set("Content-Type", "image/png")
// Send the canvas data
_, _ = io.Copy(w, canvas_img)
canvas_img.Close()
}
Going to /api/getcanvas
on my browser works well, and is identified as a png. Does a soul familiar with Pixi.js have some insight to share?
I attempted using net/http’s serveFile and using the deprecated (I believe) Pixi.js Loaders. I have also attempted miscellaneous things which I cannot remember right now.