aayush058
CDCloudflare Developers
•Created by aayush058 on 4/2/2024 in #general-help
Not able to uplod file on cloudinary.
How can i upload files to Cloudinary in the Hono app? Everything is sorted but i am not able to get the path of the file as the Cloudinarys uploader function asks for the file path.
This is the utils file of Cloudinary
import {v2 as cloudinary} from "Cloudinary"
import fs from "fs"
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET
});
const uploadOnCloudinary = async (localFilePath) => {
try {
if (!localFilePath) return null
//upload the file onCloudinaryy
const response = await cloudinary.uploader.upload(localFilePath, {
resource_type: "auto"
})
// file has been uploadedsuccessfull
//console.log("file is uploaded onCloudinaryy ", response.url);
fs.unlinkSync(localFilePath)
return response;
} catch (error) {
fs.unlinkSync(localFilePath) // remove the locally saved temporary file as the upload operation got failed
return null;
}
}
export {uploadOnCloudinary}
PROBLEM:
// i get the file but not able to get the path
// code
const body = await ctx.req.parseBody()
console.log(body["image"]);
// output
image: File {
lastModified: 1712061871701,
name: 'm5.jpg',
type: 'image/jpeg',
size: 84673
}
my refrense : https://hono.dev/api/request#parsebody2 replies