I try to POST base64 encoded jpeg image from M5Camera to another server.
I could Base64 encode using by mbedtls_base64_encode(), it seems to be fine.
but I used POST method in esp_http_client_example.c in example of esp-idf,
POST replaces charactor "+" to charactor " " in Base64 encoded text.
How can I fix this problem ?
Code: Select all
static void http_post_task(void *pvParameters)
{
esp_http_client_config_t config = {
.url = "http://httpbin.org/get",
// .event_handler = _http_event_handler,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err = esp_http_client_perform(client);
unsigned char image0[30000];
char image[30000];
size_t olen;
mbedtls_base64_encode(image0, sizeof(image0), &olen, camera_get_fb(), camera_get_data_size());
static char *HEADER = "text=";
snprintf(image, sizeof(image0)+5, "%s%s", HEADER, image0);
const char *post_data = (const char*)image;
esp_http_client_set_url(client, "http://httpbin.org/get/");
esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_post_field(client, post_data, strlen(post_data));
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP POST request failed: %s", esp_err_to_name(err));
}
while(1);
}