`convex/http.js` must have a default export of a Router.
Trying to follow instructions on https://docs.convex.dev/file-storage/upload-files#uploading-files-via-an-http-action
Error:
My code is:
Uploading and Storing Files | Convex Developer Hub
Files can be uploaded by your users and stored in Convex.
17 Replies
Ah we're missing a line in the docs. I think
export default http
is what you need? (If that works, I'll update the docs accordingly, thanks for raising!)Yes, that worked! Thank you 🙂
It's also confusing to have the same file listed twice with different contents

also running into issues with CORS:
I followed the example so:
and my .env.local has
CLIENT_ORIGIN=http://localhost:3001/
Re: docs -- yeah thanks for the feedback! In our demos they're actually two snippets in the same file (https://github.com/get-convex/convex-demos/blob/main/file-storage/convex/sendMessage.js) but definitely looks confusing
GitHub
convex-demos/sendMessage.js at main · get-convex/convex-demos
Demo apps built on Convex. Contribute to get-convex/convex-demos development by creating an account on GitHub.
And I think you might want your URL as
https://decisive-nightingale-272.convex.site/sendImage
(convex.site as opposed to convex.cloud)?I don't have .site as a value, that's just the error text
My value is localhost
I'm guessing you have something like this in your web code somewhere?
// e.g. https://happy-animal-123.convex.site/sendImage?author=User+123
const sendImageUrl = new URL(${convexSiteUrl}/sendImage
);
sendImageUrl.searchParams.set("author", name);
await fetch(sendImageUrl, {
method: "POST",
headers: { "Content-Type": selectedImage.type },
body: selectedImage,
});
Yeah:
const sendImageUrl = new URL(
${process.env.NEXT_PUBLIC_CONVEX_URL}/sendImage);
Is that wrong?
And thank you for the help @sshader, really appreciate it. I've been banging my head on this for a while 😦Yeah you might want to check your .env and .env.local files and define something like NEXT_PUBLIC_CONVEX_SITE_URL that ends with .site instead of .cloud
Ok now I have
NEXT_PUBLIC_CONVEX_URL="https://avid-badger-157.convex.cloud"
NEXT_PUBLIC_CONVEX_SITE="https://avid-badger-157.convex.site"
And changed
to use .site instead of cloud
Testing now 🙂
Still failing 😦

Hmm. Do you have an
httpAction
for sendImage
and OPTIONS
(like in https://docs.convex.dev/functions/http-actions#cors) as well as POST
? Otherwise I'd maybe try hitting that endpoint outside of a browser (e.g. via curl
) to see if it's an issue with the endpoint or CORS.
Sorry this is hard to set up :/HTTP Actions | Convex Developer Hub
HTTP actions allow you to build an HTTP API right in Convex!
Running into a larger problem, which is that I can't get it to work on Vercel. It's deployed to https://print-generator.vercel.app but keeps showing error
For build command I've tried
nextjs build && npx convex deploy
and npm run build && npx convex deploy
but both show the same error, even after pushing a change ->Github->VercelWhere do you see that error? When I try this I just see the 404s from the HTTP requests
Oh hang on, it might have just taken 10 minutes to get Vercel's act together, let me test something
Yes! It is working, I guess changing build commands takes a while to go into effect
Still stuck on the sendImage problem, but today is presentation day so that will wait 🙂
You might want to use
hono
for your http routing. Check out Sarah's post on it here: https://stack.convex.dev/hono-with-convexAdvanced HTTP Endpoints: Convex ❤️ Hono
Adding advanced HTTP Endpoint functionality by extending Convex with Hono.