Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with S3-storage #1069

Closed
zuohuadong opened this issue May 4, 2023 · 6 comments
Closed

with S3-storage #1069

zuohuadong opened this issue May 4, 2023 · 6 comments

Comments

@zuohuadong
Copy link

I've tried a lot of ways to use S3 storage, but I get an error on hono, can you give me a little advice?

import { Context } from "hono";

import AWS from "aws-sdk";
import { S3Client } from '@aws-sdk/client-s3'
import multer from "multer";
import multerS3 from "multer-s3";

export default async (context: Context) => {
    const body = await context.req.parseBody();
    console.log(body);
    const fileBuffer:File = body.file;

    const s3Client = new S3Client({
        credentials: {
            accessKeyId: process.env.S3_ACCESS_KEY, // accessKeyId that is stored in .env file
            secretAccessKey: process.env.S3_SECRET_KEY, // secretAccessKey is also store in .env file
        },
        region: process.env.S3_REGION,
        endpoint: process.env.S3_ENDPOINT,
        forcePathStyle: true,
    });

    multer({
        storage: multerS3({
            s3: s3Client,
            bucket: process.env.S3_BUCKET,
            shouldTransform: true,
            acl: "private",
            metadata: function (req, fileBuffer, cb) {
                cb(null, { fieldName: fileBuffer._name });
            },
            key: function (req, fileBuffer, cb) {
                cb(null, Date.now().toString());
            },
        }),
    })


    return context.json({
        file: fileBuffer,
        StorageS3: s3Client
        // multerS3Config: multerS3Config,
    });
}


@yusukebe
Copy link
Member

yusukebe commented May 9, 2023

Hi @zuohuadong

Which platform do you want to run it on? Node.js, Cloudflare Workers, Deno, or Bun?

@zuohuadong
Copy link
Author

@yusukebe node.js ,thanks

@yusukebe
Copy link
Member

yusukebe commented May 9, 2023

First, you have to use Node.js Adapter:

https://github.com/honojs/node-server

@Manouchehri
Copy link
Contributor

For using S3 storage, you can use the lightweight aws4fetch library. https://github.com/mhart/aws4fetch

I use it a ton with Cloudflare Workers and Hono.

@yusukebe
Copy link
Member

You may use Hono Storage:

https://github.com/sor4chi/hono-storage

@yusukebe
Copy link
Member

yusukebe commented Jan 9, 2024

There is no update. Closing this issue.

@yusukebe yusukebe closed this as completed Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants