Invalid JSON response from server

arthurgps2 Member Posts: 3

Hello. So in my Spring application I have this CloudinaryService class with this function that's supposed to take a Base64-enconded image and upload it to Cloudinary:

public String uploadFileFromBase64(String base64) {
		try {
			Map uploadedFile = cloudinary.uploader().upload(base64, // the error is being thrown in this line
			String publicId = (String) uploadedFile.get("public_id");
			return cloudinary.url().secure(true).generate(publicId);
		} catch (IOException e) {
			return null;

and I'm calling it like this:

String thumbnail = form.get("thumbnail");
String cardImageUrl = cloudinaryService.uploadFileFromBase64(thumbnail);

But for some reason, whenever it tries to upload the image, it throws this error:

Invalid JSON response from server A JSONObject text must begin with '{' at 1 [character 2 line 1]

I'm not really sure what's causing this because I used a similar method in another project and it worked fine.

Best Answer

  • arthurgps2
    arthurgps2 Member Posts: 3
    Answer ✓

    That was it, the credentials. I had them defined in the CloudinaryConfiguration class like this:

    private String cloudName;
    private String apiKey;
    private String apiSecret;

    The @Value annotation wasn't taking the values set in because I wrote the value in the parenthesis wrong. The moment I corrected it...

    private String cloudName;
    private String apiKey;
    private String apiSecret;

    it started working right back again. It had to do with my own config, after all. Thanks for the help!


  • Cloudinary Team
    Cloudinary Team Administrator, Cloudinary Staff Posts: 113 admin

    Hi Arthur,

    Thanks for contacting us.
    In general, the error you are receiving indicates that the upload call is receiving an error response due to a failure, but the error that was returned as an HTML page wasn't parsed successfully and you couldn't see the actual cause for the failure.

    When the check the logs for your cloud -

    The only error listed says "ResourceInvalid: Empty file"

    Would it be possible to confirm that you're passing a valid base64 and not an empty value?


    Helpful Links For You
    💬 Share questions, connect with other users in our Cloudinary Community forums and Discord server!
    🧑‍🎓 Join our Cloudinary Academy for free courses, workshops and other educational resources.
    📄 Read our documentation for in-depth details on Cloudinary product features and capabilities
    📰 Check out the Cloudinary blog for the latest company news and insights

  • arthurgps2
    arthurgps2 Member Posts: 3

    Okay, I just checked it using


    where the "thumbnail" form is where the image is supposed to be. This is what I got:


    So yeah, that's a base64 image right there

  • Cloudinary_John_H
    Cloudinary_John_H Member, Cloudinary Staff Posts: 32

    Hi Arthur,

    Can you paste the full base64, so I can decode it and confirm that it loads successfully?

    Also, the last logs that mention your cloud name are from February 4 - have run the upload call since then?

    If you have, please double-check your credentials, the call may not be reaching us.

    Looking forward to your response,


  • Cloudinary_John_H
    Cloudinary_John_H Member, Cloudinary Staff Posts: 32

    Wonderful, glad you were able to figure it out!