Kay
Kay5mo ago

Get image data from automated download

I have this page which displays a render using threejs and renders it into a png and downloads it. i need that image to use it in a canvas from deno-canvas but when i download it using this package it returns this 'C:\Users\titul\AppData\Local\Temp\deno_dwldf3d5cf300f407d23/E:\Arcunis\recipeImageMaker\stone.png' code where i download it:|
import { download } from "https://deno.land/x/download@v2.0.2/mod.ts";
export default async function generateBlock(block: String) {
await download("http://localhost:8000/renderer/index.html?material=" + block, {file: Deno.cwd() + "\\stone.png"});
}
import { download } from "https://deno.land/x/download@v2.0.2/mod.ts";
export default async function generateBlock(block: String) {
await download("http://localhost:8000/renderer/index.html?material=" + block, {file: Deno.cwd() + "\\stone.png"});
}
1 Reply
Deno AI Helper
Deno AI Helper5mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you provided, there might be a potential issue with the way you are constructing the file path for the download destination. In the download function, you are using Deno.cwd() + "\\stone.png" to specify the file path. This could potentially lead to path issues, especially if Deno.cwd() returns a path that does not end with a backslash. It's generally safer to use Deno.cwd() in combination with Deno.build.os to check the operating system and use the appropriate path separator, or better yet, use the path module from Deno's standard library to join paths in a cross-platform way. Here's a revised version of your code using the path module:
import { download } from "https://deno.land/x/download@v2.0.2/mod.ts";
import { join } from "https://deno.land/std/path/mod.ts";

export default async function generateBlock(block: string) {
const filePath = join(Deno.cwd(), "stone.png");
await download(`http://localhost:8000/renderer/index.html?material=${block}`, { file: filePath });
}
import { download } from "https://deno.land/x/download@v2.0.2/mod.ts";
import { join } from "https://deno.land/std/path/mod.ts";

export default async function generateBlock(block: string) {
const filePath = join(Deno.cwd(), "stone.png");
await download(`http://localhost:8000/renderer/index.html?material=${block}`, { file: filePath });
}
Please note that the advice provided here is not based on the Deno documentation, and you should double-check the accuracy of the advice given. Additionally, ensure that the URL you are downloading from is correct and that the server is configured to serve the image as expected.