Uploadthing uploading directly from express server

I am using Whatsapp Cloud API from which I am receiving different types of messages and processing it. For processing Images, Whatsapp sends the image in binary format which I am getting in my express server with responseType: "arraybuffer" format. I want to upload this image directly to uploadthing once I receive it from the Whatsapp API. How to go about this? I have setup the following from the uplaodthing website express code - /api/uploadthing route in my express server - uploadthing.js copying the express code on uploadthing website (file is attached here) I am confused how to actually upload the image is there some upload function in the sdk or doing an axios.post to the api available to me? Thanks for the help !
1 Reply
Bumble
Bumble8mo ago
import { UTApi } from "uploadthing/server";

const utapi = new UTApi();

// Upload image to UT
const metadata = {};
const uploadResponse = await utapi.uploadFiles(new File([<binary image>], <image name>), { metadata });

// handle upload error
if (uploadResponse.error) {
// handle error
}

// handle upload success
const uploadedImg = uploadResponse.data;
import { UTApi } from "uploadthing/server";

const utapi = new UTApi();

// Upload image to UT
const metadata = {};
const uploadResponse = await utapi.uploadFiles(new File([<binary image>], <image name>), { metadata });

// handle upload error
if (uploadResponse.error) {
// handle error
}

// handle upload success
const uploadedImg = uploadResponse.data;
Make sure to replace <binary image> and <image name> with the correct values. Upload thing server api documentation https://docs.uploadthing.com/api-reference/ut-api#utapi
Want results from more Discord servers?
Add your server