TotallyDark
TotallyDark8mo ago

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?
No description
No description
6 Replies
lee
lee8mo ago
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
TotallyDark
TotallyDarkOP8mo ago
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.
lee
lee8mo ago
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/
PyPI
convex
Python client for the reactive backend-as-a-service Convex.
ian
ian8mo ago
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
TotallyDark
TotallyDarkOP8mo ago
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.
Michal Srb
Michal Srb8mo ago
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:
import requests

# Assuming selectedImage is a file-like object or a path to a file
selected_image = open('selected_image.jpg', 'rb')

send_image_url = 'your_send_image_url'

response = requests.post(send_image_url, files={'file': selected_image})

selected_image.close() # Close the file after uploading

# Check response status
if response.ok:
print("Image uploaded successfully")
else:
print("Failed to upload image")
import requests

# Assuming selectedImage is a file-like object or a path to a file
selected_image = open('selected_image.jpg', 'rb')

send_image_url = 'your_send_image_url'

response = requests.post(send_image_url, files={'file': selected_image})

selected_image.close() # Close the file after uploading

# Check response status
if response.ok:
print("Image uploaded successfully")
else:
print("Failed to upload image")
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.

Did you find this page helpful?