Image to base64 throwing an 500 error
Hi, am working on project where there is wholesaler create form that needs to post image and other few datas. The api takes application/json as reqHeaders so, I am trying to convert the image as a base64string but on submitting it throws this error
9 Replies
"Data too long for column 'image' at row 1" means just what it says. You're sending too much data for it to fit in that column
I have shared the code where the base64 conversion take place , if possible could you point what is going wrong?
the input file is too big
it's not in the code, most likely
is this a backend you wrote?
no
do you have documentation for it? Or is it from a different team in your company?
somewhere in the schema for the database, there's a maximum size defined for the image column. The image you're uploading is exceeding that maximum size. You can either use a smaller image, write code to convert / resize / compress the image before converting to base64, or contact whoever wrote the database and ask them to increase the size limit
Ok, I will try to compress the image before conversion
I tried the compression but still ended with same error, so is there any other ways to upload files to a content-type of application/json instead of base64 conversion
Again, the file is likely still too big. Are you even supposed to upload a file in base64 to that field? Or should it be a url? Have you checked the documentation for the api?
I have checked the api docs and deliverd my issue with backend team, and they changed the content-type to mulipart/formdata so that file size wont be a problem anymore. I appreciate your effort on helping me to resolve the issue, Thank You.
if i were you, i would still look into handling errors, as the server should have a file limit that it rejects
for example, if some user tries to upload a 6gb iso file as an image (renamed to have .jpg) your server may reject the upload or even reject the request once it received too much data