Pushing Generated PNG to Convex DB
Hi, so I have a png image that I want to push to my Convex DB, I am following this tutorial to do so: https://docs.convex.dev/file-storage/store-files. However, when importing the image to my .ts file trying to store in my by database with following code
import img from '../TodayImg.png'
const image = await img.blob();
const storageId: Id<"_storage"> = await ctx.storage.store(image)
(attatched code and error message)
I am getting a "No loader is configured for ".png" files" error. Does anyone know how I can fix this?6 Replies
if you have the png already, i would add it to convex storage directly through the dashboard ui https://dashboard.convex.dev/deployment/files . Uploading a png as part of the code pushed to convex (as you are trying to do) is not currently supported
Convex Dashboard
Manage your Convex apps
uploading the image using the dashboard ui isn't really going to work for me because the PNG image is an image that is generated by a python script which runs once per day and produces a different image each time. Is this really not possible though?
All I want is something that is similar to upload files button from https://uploadstuff.dev/getting-started/server-setup, but instead of asking the user to upload, upload straight from the code.
can you describe how this daily-generated png happens? what runs the python? Maybe you could use a python client to upload to convex whenever the image is generated https://pypi.org/project/convex/
Uploading it to a url is probably your best bet. If it’s really small you could just pass it as a parameter to an action
how do I pass it as a parameter to an action?
Yeah, so the python script runs on a linux ubuntu VM and it collects a pdf from a website. Then in the python program, it manipulate the pdf and spit out an image and some text, both of which I want to host on Convex so that I could pull from it for an Expo app I am working on. The text I have already gotten working on convex with mutations, but I have no idea how I would do the same for the photo.
So on Convex side, you can define an HTTP action to accept the file:
https://docs.convex.dev/file-storage/upload-files#defining-the-upload-http-action
On the Python side, I'm not sure, but ChatGPT told me:
If that doesn't work Google more for "sending file from Python to an HTTP endpoint".
Uploading and Storing Files | Convex Developer Hub
Files can be uploaded by your users and stored in Convex.