diff --git a/examples/_data.ts b/examples/_data.ts index b3669f778..65ce5321e 100644 --- a/examples/_data.ts +++ b/examples/_data.ts @@ -198,6 +198,11 @@ export const sidebar = [ href: "/examples/webassembly/", type: "example", }, + { + title: "Create object URL", + href: "/examples/create_object_url/", + type: "example", + }, ], }, diff --git a/examples/scripts/create_object_url.ts b/examples/scripts/create_object_url.ts new file mode 100644 index 000000000..543ebafd0 --- /dev/null +++ b/examples/scripts/create_object_url.ts @@ -0,0 +1,185 @@ +/** + * @title Generate downloadable files + * @difficulty beginner + * @tags web + * @run --allow-net + * @resource {https://docs.deno.com/api/web/~/URL.createObjectURL } Doc: Deno.createObjectURL + * @group Web Standard APIs + * + * Demonstrates using URL.createObjectURL() to create a downloadable text file from in-memory content. + */ + +// Create a basic HTML page with JavaScript that uses URL.createObjectURL() +const html = ` + + + URL.createObjectURL Demo + + + +

URL.createObjectURL Examples in Deno

+ +
+

Example 1: Generate Downloadable Text File

+ +

Creates a Blob containing text and generates a downloadable link

+
+ +
+

Example 2: Generate JSON File

+ +

Creates a Blob containing JSON data and generates a downloadable link

+
+ +
+

Example 3: Draw on Canvas and Export

+ +
+ + +
+

Draw on the canvas above and download the result as a PNG image

+
+ + + +`; + +// Start a simple server to serve the HTML page +console.log("Starting server at http://localhost:8000"); +await Deno.serve((req) => { + return new Response(html, { + headers: { "content-type": "text/html; charset=utf-8" }, + }); +}, { port: 8000 });