pyTelegrambotAPI with convex, cant get image to be sent sometimes
I have a telegram bot that disperses information on seating areas of schools, when queried, it will send an image.
I store the images in convex file system and retrieve the images using the following function
export const getImg = query({
args: { photoId: v.string() },
handler: async (ctx, { photoId }) => {
return await ctx.storage.getUrl(photoId);
},
});
However, i would occasionally get the error
"A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: wrong file identifier/HTTP URL specified"
for some schools and will only be fixed when i reupload the image and replace the fileId of the school record
a school record looks like this:
mrt_schools: defineTable({
school_name: v.string(),
seating_sector: v.string(),
}).index("by_school_name", ["school_name"])
where seating_sector is the fileId in storage and school_name is the name of the school
How can i prevent this? It doesnt seem to happen on my Nextjs project but only this project
It happens to random schools as well, even after testing some schools, it would throw this error on the tested schools that intially sent the image of the seating sector
10 Replies
Hi @rochel3. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided, it seems like the issue might be related to the retrieval of the image URL from the Convex storage. The error message "Bad Request: wrong file identifier/HTTP URL specified" suggests that the URL being used to fetch the image from the Convex storage might be incorrect or expired.
In Convex, the storage URLs are temporary and they expire after a certain period of time. If you are storing the URL and using it at a later time, it might have expired causing the error. Instead, you should always fetch the URL when you need it using the
getImg
function you have defined.
If the issue persists, it might be due to some other factors not covered in the provided knowledge sources. It would be helpful to check the Convex logs for any errors or warnings when the issue occurs. You can also reach out to the Convex support team for further assistance.
As for the issue not occurring in your Next.js project, it could be due to differences in how the projects are set up or how they interact with the Convex storage. Without more information, it's hard to pinpoint the exact cause.
Here is the reference to the Convex documentation for File Storage with HTTP actions (https://docs.convex.dev/file-storage#file-storage-with-http-actions) which might be helpful.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@263225706849239040> kapa.ai is still learning and improving, please let us know how it did by reacting below
Could it be IP throttling? It doesn't really sound Convex-related, expect for maybe our IPs are different to your Next.js server (but maybe your Next.js server request volume is lower too?).
It could also be some application bug.
re application bug, do you ever delete these seating charts? When you fix by
fixed when i reupload the image and replace the fileId of the school recordreal curious if the old image is still there
@ballingt Nope i do not delete those seating charts. When i head to the old files that did not work and hovered over them , it still showed the correct image that was supposed to be sent
@rochel3 Do you call getUrl() each time you need it? or do you store the link and reuse it?
I use getUrl() each time i use it
What's going on with the Telegram API here, could you print these URLs when this error happens?
Like Michal said, this error isn't coming from Convex
Can i check if it is the correct practice to getUrl() everytime i need the image? Or is it better if i just store the URL
getUrl is safer, because urls may eventually expire