Skip to content

Releases: sor4chi/hono-storage

@hono-storage/[email protected]

14 Oct 11:05
3754945
Compare
Choose a tag to compare

Patch Changes

@hono-storage/[email protected]

14 Oct 13:38
9a654c3
Compare
Choose a tag to compare

Patch Changes

  • #9 845d497 Thanks @sor4chi! - Introduced a new storage called MemoryStorage!

    This storage is useful for testing and prototyping, but should not be used in production.

    import { serve } from "@hono/node-server";
    import { HonoMemoryStorage } from "@hono-storage/memory";
    import { Hono } from "hono";
    
    const app = new Hono();
    const storage = new HonoMemoryStorage({
      key: (c, file) => `${file.originalname}-${new Date()}`,
    });
    
    app.post("/", storage.single("file"), (c) => c.text("OK"));
    app.get("/list", (c) => c.json(storage.buffer.forEach((file) => file.name)));
    
    serve(app);

@hono-storage/[email protected]

14 Oct 11:05
3754945
Compare
Choose a tag to compare

Patch Changes

  • #7 ea1eb7a Thanks @sor4chi! - file helper for HonoStorage

    import { HonoStorageFile } from "@hono-storage/core";
    
    const file = new File([blob], "filename.ext.zip");
    const HSfile = new HonoStorageFile(file);
    HSfile.originalname; // => name part of file (filename.ext)
    HSfile.extensiton; // => extension part of file (.zip)

@hono-storage/[email protected]

13 Oct 18:22
7e3f4ad
Compare
Choose a tag to compare

Patch Changes

  • #3 da24913 Thanks @sor4chi! - Support more dynamic dest path.
    You can decide the dest path by the context and file.

    Before

    const storage = new NodeDiskStorage({
      dest: "/path/to/dest",
    });

    After

    Also support function.

    const storage = new NodeDiskStorage({
      dest: (c, file) => {
        return "/path/to/dest";
      },
    });

@hono-storage/[email protected]

12 Oct 18:31
89ea287
Compare
Choose a tag to compare

Patch Changes

  • 472a0a3 Thanks @sor4chi! - This is Hono Storage for Node.js, a simple and easy to use file storage library.

    npm install @hono-storage/node-disk
    import { serve } from "@hono/node-server";
    import { HonoDiskStorage } from "@hono-storage/node-disk";
    import { Hono } from "hono";
    
    const app = new Hono();
    const storage = new HonoDiskStorage({
      dest: "./uploads",
      filename: (c, file) =>
        `${file.originalname}-${Date.now()}.${file.extension}`,
    });
    
    app.post("/upload", storage.single("image"), (c) => c.text("OK"));
    
    serve(app);
  • Updated dependencies [a7ade7f]:

@hono-storage/[email protected]

12 Oct 18:31
89ea287
Compare
Choose a tag to compare

Patch Changes

  • a7ade7f Thanks @sor4chi! - This is Hono Storage, a simple and easy to use file storage library.

    npm install @hono-storage/core
    import { HonoStorage } from "@hono-storage/core";
    import { Hono } from "hono";
    
    const app = new Hono();
    const storage = new HonoStorage({
      storage: (c, files) => {
        // do something with the files, eg, upload to s3, or save to local, etc.
      },
    });
    
    app.post("/upload/single", storage.single("image"), (c) => c.text("OK"));
    app.post("/upload/array", storage.array("pictures"), (c) => c.text("OK"));
    app.post(
      "/upload/field",
      storage.fields([
        { name: "image", maxCount: 1 },
        { name: "pictures", maxCount: 2 },
      ]),
      (c) => c.text("OK"),
    );
    
    // and you can get parsed formData easily
    app.post("/upload/vars", storage.single("image"), (c) => {
      const { image } = c.get("files");
      // do something with file
      return c.text("OK");
    });