Here is a bit of my code. Download request GET function:
Code: Select all
void http_get_file() {
esp_http_client_config_t config_get = {
.url = "https://download.samplelib.com/wav/sample-15s.wav",
.method = HTTP_METHOD_GET,
.cert_pem = (const char *)certs_pem_start,
.event_handler = client_event_get_handler};
esp_http_client_handle_t client = esp_http_client_init(&config_get);
esp_http_client_perform(client);
esp_http_client_cleanup(client);
}
Code: Select all
esp_err_t client_event_get_handler(esp_http_client_event_handle_t evt) {
ESP_LOGI(TAG, "Opening file %s", file_wav);
FILE *sd_f = fopen(file_wav, "a");
if (sd_f == NULL) {
ESP_LOGE(TAG, "Failed to open file for writing");
return ESP_FAIL;
}
switch (evt->event_id) {
case HTTP_EVENT_ON_DATA:
fwrite(evt->data, 1, evt->data_len, sd_f);
break;
default:
break;
}
fclose (sd_f);
return ESP_OK;
}