You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
here is my implementation of code
import { Hono } from "hono";
import { S3Client } from "@aws-sdk/client-s3";
import { HonoS3Storage } from "@hono-storage/s3";
Your code is actually already set up regarding uploading.
The actual uploading process is written in the storage.single middleware, so it actually works on its own.
here is my implementation of code
import { Hono } from "hono";
import { S3Client } from "@aws-sdk/client-s3";
import { HonoS3Storage } from "@hono-storage/s3";
const client = (accessKeyId: string, secretAccessKey: string) =>
new S3Client({
region: "ap-southeast-2",
credentials: {
accessKeyId,
secretAccessKey,
},
});
const storage = new HonoS3Storage({
key: (_, file) =>
${file.originalname}-${new Date().getTime()}.${file.extension},
bucket: "myblogiumbk1",
client: (c) => client(c.env.AWS_ACCESS_KEY_ID, c.env.AWS_SECRET_ACCESS_KEY),
});
userRoute.post('/api/upload', storage.single("file"), async (c) => {
try {
const { file } = await c.req.parseBody();
// Check if file exists and has a name
if (!file ) {
return c.json({ error: "Missing file or filename in request" }, 400);
}
// Upload the file using storage
// ... (your upload logic)
return c.text("Image uploaded successfully!");
} catch (e) {
console.error(e);
return c.json({ error: "Internal server error" }, 500);
}
});
can anyone tell me how to change my code so that I can upload image from when user inputs it and store it in my bucket
The text was updated successfully, but these errors were encountered: