Download file from presigned url

MaxLink
Posts: 2
Joined: Fri Apr 28, 2023 9:31 am

Download file from presigned url

Postby MaxLink » Fri Apr 28, 2023 10:04 am

I'm trying to download a text-file from a pre-sigend AWS S3 url using the esp http client but I'm running into some issues. With the code-sample appended at the end of the post, I can download the Google logo (the url used), the sequence of events will be something like:

Code: Select all

HTTP_EVENT_ON_CONNECTED
HTTP_EVENT_HEADER_SENT
HTTP_EVENT_ON_HEADER
HTTP_EVENT_ON_HEADER
more HTTP_EVENT_ON_HEADER ...
HTTP_EVENT_ON_DATA
more HTTP_EVENT_ON_DATA ...
HTTP_EVENT_ON_FINISH
HTTP_EVENT_DISCONNECTED
While, if I used a pre-signed url for a file on S3 I only get:

Code: Select all

HTTP_EVENT_ON_CONNECTED
HTTP_EVENT_ERROR
HTTP_EVENT_DISCONNECTED
I verified both links in Python, and this row works fine for both urls:

Code: Select all

requests.get(url, verify=False)

I'm using ESP-IDF 4.4 and I've set the following in the config:
  • Enable ESP-TLS Serve
  • Allow potentially insecure options
  • Skip server certificate verification by default



Anyone who has seen anything similar, has tried downloading from a pre-signed S3 link or has any idea how I can debug this?

BR
Max

Code: Select all

esp_err_t _https_event_handle(esp_http_client_event_t *evt) {
    switch(evt->event_id) {
        case HTTP_EVENT_ERROR:
            cout << "HTTP_EVENT_ERROR" << endl;
            break;
        case HTTP_EVENT_ON_CONNECTED:
            cout << "HTTP_EVENT_ON_CONNECTED" << endl;
            break;
        case HTTP_EVENT_HEADER_SENT:
            cout << "HTTP_EVENT_HEADER_SENT" << endl;
            break;
        case HTTP_EVENT_ON_HEADER:
            cout << "HTTP_EVENT_ON_HEADER" << endl;
            break;
        case HTTP_EVENT_ON_DATA:
            cout << "HTTP_EVENT_ON_DATA" << endl;
            break;
        case HTTP_EVENT_ON_FINISH:
            cout << "HTTP_EVENT_ON_FINISH" << endl;
            break;
        case HTTP_EVENT_DISCONNECTED:
            cout << "HTTP_EVENT_DISCONNECTED" << endl;
            break;
    }
    return ESP_OK;
}

void get_data()
{
    esp_http_client_config_t config = {
        .url = "https://www.google.se/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png",
        .cert_pem = NULL,
        .method = HTTP_METHOD_GET,
        .timeout_ms = 10000,
        .event_handler = _https_event_handle,
        .transport_type = HTTP_TRANSPORT_OVER_SSL,
    };
    esp_http_client_handle_t client = esp_http_client_init(&config);
    esp_err_t err = esp_http_client_perform(client);
    esp_http_client_cleanup(client);
}

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Download file from presigned url

Postby MicroController » Mon May 01, 2023 3:54 pm

any idea how I can debug this?
Well, how about starting by logging what error is reported?

MaxLink
Posts: 2
Joined: Fri Apr 28, 2023 9:31 am

Re: Download file from presigned url

Postby MaxLink » Tue May 02, 2023 6:55 am

That would make a lot of sense, yes. Sadly I've done this, just a while ago so I forgot to include it in the post, sorry for that. The error from esp_http_client_perform is just a generic -1.The data in esp_http_client_event_t has length 0. So I am assuming that means no information, but I haven't found any example for how you could get additional error info from the event. And the struct seem to only have id, data, user-data and header(only for header event). Or is there a way of getting something more out of it?

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Download file from presigned url

Postby MicroController » Sat May 06, 2023 11:40 am


Who is online

Users browsing this forum: No registered users and 113 guests