Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i would like to convert an image to Base64-encoded in esp32 cam . already i used method under detail like this : ConvertBase64("D:/ok.jpg","D:/encode_Folder"); but not working (encode_Folder is empty)
void ConvertBase64(String jpgpath, String base64path) {
Process p;
p.begin("/mnt/sda1/base64.sh");
p.addParameter(jpgpath);
p.addParameter(base64path);
p.run();
while(p.running());
}

What I have tried:

maybe another/right way is using method under detail : static String encode(const uint8_t * data, size_t length, bool doNewLines = true); but i dont know how to use above method . would you please help me?
Posted
Updated 3-Aug-21 15:50pm

1 solution

I found this blog post article on Base64 encoding on Arduino.

Here is the relevant block of code from the article

size_t size = image.size;
const uint8_t* image = image.data;

uint8_t *buffer = calloc((size + 2 - ((size + 2) % 3)) / 3 * 4 + 1, sizeof(char));
// <--- equation from internet
size_t buff_size = 0;
int err = mbedtls_base64_encode(buffer, (size + 2 - ((size + 2) % 3)) / 3 * 4 + 1,
&buff_size, image, size);
if (err != 0) {
    ESP_LOGE(TAG, "error base64 encoding, error %d, buff size: %d", err, buff_size);
    return; <pre lang="text">

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900