0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Deno KVで画像アップロード【Imgur】

Posted at

See the Pen Deno Imgur by John Doe (@04) on CodePen.

Deno KVに画像を保存してみました!

import { serve } from "https://deno.land/std@0.177.0/http/server.ts";

const kv = await Deno.openKv();

serve(async (req: Request) => {
    const filename = new URL(req.url).pathname.slice(1)
    if (req.method === 'GET') {
        const { value } = await kv.get([filename])
        return new Response(value)
    } else if (req.method === 'POST') {
        const form = await req.formData()
        const file = form.get('file')
        await kv.set([filename], await file.arrayBuffer())
        return new Response('201 Created', { headers: { 'Access-Control-Allow-Origin': '*' } })
    }
})
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?