POST replaces charactor "+" to charactor " " in Base64 encoded text

dinosauria123
Posts: 5
Joined: Fri Oct 05, 2018 6:10 pm

POST replaces charactor "+" to charactor " " in Base64 encoded text

Postby dinosauria123 » Tue Oct 23, 2018 6:14 am

Hi,

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);
}


ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: POST replaces charactor "+" to charactor " " in Base64 encoded text

Postby ESP_Sprite » Wed Oct 24, 2018 2:12 am

My guess would be that you send the data as a form field; these normally are urlencoded, even in a POST.

Who is online

Users browsing this forum: Baidu [Spider], YaCy [Bot] and 110 guests