Download Client Redirect Querry

Hi,

I am using download_client to get a bigger file (100KB) to my memory via LTE-M. The Files are located in a bucket and I use a shortURL to get the signedDownload URL. If I use this short URL in Download Client I get the Error "http/1.1 301 moved permanently". This seems to be correct, the URL is initialy ofcourse a redirect. But how can I handle this in my code? I couldnt find a way to read the header files with download client nor do I see any option for redirect hops or something like this. Is there even a solution? Or is it the limits of the low level integration?

Thanks for helping and best regards

daniel

Parents
  • Hi Daniel,

    The Files are located in a bucket and I use a shortURL to get the signedDownload URL.

    Can you show how (and where in code) you use this shortURL?

    If I use this short URL in Download Client I get the Error "http/1.1 301 moved permanently"

    Can you provide full log which contains the error?

    Best regards,
    Dejan

  • The ShortUrl is generated on a Serverside and send to the device. I can give you some snippet that shows how it works.

    prj.conf:

    # Download Client
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    CONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_DBG=y


    there is Downloader:
    #define URL "http://ul1.epaperframe.de/NDUmX2z.dl"
    static struct download_client downloader;
    static struct download_client_cfg config = {};      
          
            if (awsGetCloudConnected() && !doOnce) {
                doOnce = true;
                LOG_INF("[MAIN] DL INIT");
                int err = download_client_init(&downloader, callbackDl);
                if (err) {
                    printk("[MAIN] Failed to initialize the client, err %d", err);
                }
    
                err = download_client_get(&downloader, URL, &config, URL, 0);
                if (err) {
                    printk("[MAIN] Failed to start the downloader, err %d", err);
                    return 0;
                }
    
                printk("[MAIN] Downloading %s\n", URL);
            }
    
            if (dlClientDone) {
                dlClientDone = false;
                char recoverDataStr[2050] = {};
                strncpy(recoverDataStr, downloader.buf, sizeof(recoverDataStr));
                printk("[DL] Payload: \"%s\"\n", recoverDataStr);
            }

    And there is the callback:

    static int callbackDl(const struct download_client_evt *event) {
        static size_t downloaded;
        static size_t file_size;
    
        if (downloaded == 0) {
            download_client_file_size_get(&downloader, &file_size);
            downloaded += 0;
        }
    
        switch (event->id) {
            case DOWNLOAD_CLIENT_EVT_FRAGMENT:
                downloaded += event->fragment.len;
                if (file_size) {
                    progress_print(downloaded, file_size);
                    char recoverDataStr[2200] = {};
                    strncpy(recoverDataStr, event->fragment.buf, event->fragment.len);
                    printk("%s \n", recoverDataStr);
                } else {
                    printk("\r[ %d bytes ] ", downloaded);
                }
                return 0;
            case DOWNLOAD_CLIENT_EVT_CLOSED:
                printk("[DL] CLOSED\n");
                dlClientDone = true;
                return 0;
            case DOWNLOAD_CLIENT_EVT_DONE:
                printk("[DL] DONE\n");
                return 0;
            case DOWNLOAD_CLIENT_EVT_ERROR:
                printk("[DL] Error %d during download\n", event->error);
                return -1;
        }
        return 0;
    }

    I am not sure what you mean by more log, but here is a sample output with LOG DEBUG (DOWNLOAD_CLIENT_LOG_LEVEL_DBG):

    00> *** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
    00> *** Using Zephyr OS v3.6.99-100befc70c74 ***
    00> I: [MAIN] Starting application 2.0.1
    00> I: 16 Sectors of 4096 bytes
    00> I: alloc wra: 2, fc0
    00> I: data wra: 2, a20
    00> I: [LED] led sample
    00> I: [SPI] init
    00> I: [DISPLAY] sleep start
    00> I: [DISPLAY] WAIT finished
    00> I: [DISPLAY] sleep done
    00> I: [MAIN] Chip is NEW - set LTE-M
    00> I: [MODEM] Modem Band Lock Set
    00> I: [MODEM] Version: 2.0.1
    00> I: [MODEM] Network registration status: Connected - roaming
    00> I: [MODEM] PSM parameter update: TAU: 3240, Active time: -1
    00> I: [MODEM] client_id: nrf-35940*
    00> I: [AWS] iot_connect - init done
    00> W: [AWS] iot_reconnect - wait 30 s connect try: 1/30
    00> W: [AWS] IOT_EVT_CONNECTED
    00> I: [MODEM] BOOT Image Confirmed
    00> I: [MAIN] DL INIT
    00> D: state = 1
    00> I: Downloading: http://ul1.epaperframe.de/NDUmX2z.dl [0]
    00> [MAIN] Downloading http://ul1.epaperframe.de/NDUmX2z.dl
    00> D: Port not specified, using default: 80
    00> D: Failed to resolve hostname ul1.epaperframe.de on IPv6
    00> D: family: 1, type: 1, proto: 6
    00> I: Connecting to 3.5.134.246
    00> D: fd 1, addrlen 8, fam IPv4, port 80
    00> D: state = 2
    00> D: Receiving up to 2048 bytes at 0x2000cbd8...
    00> D: Read 620 bytes from socket
    00> D: GET header size: 620
    00> E: Unexpected HTTP response: 301 moved permanently
    00> [DL] Error -77 during download
    00> D: state = 4
    00> D: state = 0
    00> [DL] CLOSED
    00> D: Connection closed
    00> [DL] Payload: "http/1.1 301 moved permanently"

    The links are save to stay public But they wont work anymore after some time

    The Download Client Sample worked fine btw. so thats not the issue.

Reply
  • The ShortUrl is generated on a Serverside and send to the device. I can give you some snippet that shows how it works.

    prj.conf:

    # Download Client
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    CONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_DBG=y


    there is Downloader:
    #define URL "http://ul1.epaperframe.de/NDUmX2z.dl"
    static struct download_client downloader;
    static struct download_client_cfg config = {};      
          
            if (awsGetCloudConnected() && !doOnce) {
                doOnce = true;
                LOG_INF("[MAIN] DL INIT");
                int err = download_client_init(&downloader, callbackDl);
                if (err) {
                    printk("[MAIN] Failed to initialize the client, err %d", err);
                }
    
                err = download_client_get(&downloader, URL, &config, URL, 0);
                if (err) {
                    printk("[MAIN] Failed to start the downloader, err %d", err);
                    return 0;
                }
    
                printk("[MAIN] Downloading %s\n", URL);
            }
    
            if (dlClientDone) {
                dlClientDone = false;
                char recoverDataStr[2050] = {};
                strncpy(recoverDataStr, downloader.buf, sizeof(recoverDataStr));
                printk("[DL] Payload: \"%s\"\n", recoverDataStr);
            }

    And there is the callback:

    static int callbackDl(const struct download_client_evt *event) {
        static size_t downloaded;
        static size_t file_size;
    
        if (downloaded == 0) {
            download_client_file_size_get(&downloader, &file_size);
            downloaded += 0;
        }
    
        switch (event->id) {
            case DOWNLOAD_CLIENT_EVT_FRAGMENT:
                downloaded += event->fragment.len;
                if (file_size) {
                    progress_print(downloaded, file_size);
                    char recoverDataStr[2200] = {};
                    strncpy(recoverDataStr, event->fragment.buf, event->fragment.len);
                    printk("%s \n", recoverDataStr);
                } else {
                    printk("\r[ %d bytes ] ", downloaded);
                }
                return 0;
            case DOWNLOAD_CLIENT_EVT_CLOSED:
                printk("[DL] CLOSED\n");
                dlClientDone = true;
                return 0;
            case DOWNLOAD_CLIENT_EVT_DONE:
                printk("[DL] DONE\n");
                return 0;
            case DOWNLOAD_CLIENT_EVT_ERROR:
                printk("[DL] Error %d during download\n", event->error);
                return -1;
        }
        return 0;
    }

    I am not sure what you mean by more log, but here is a sample output with LOG DEBUG (DOWNLOAD_CLIENT_LOG_LEVEL_DBG):

    00> *** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
    00> *** Using Zephyr OS v3.6.99-100befc70c74 ***
    00> I: [MAIN] Starting application 2.0.1
    00> I: 16 Sectors of 4096 bytes
    00> I: alloc wra: 2, fc0
    00> I: data wra: 2, a20
    00> I: [LED] led sample
    00> I: [SPI] init
    00> I: [DISPLAY] sleep start
    00> I: [DISPLAY] WAIT finished
    00> I: [DISPLAY] sleep done
    00> I: [MAIN] Chip is NEW - set LTE-M
    00> I: [MODEM] Modem Band Lock Set
    00> I: [MODEM] Version: 2.0.1
    00> I: [MODEM] Network registration status: Connected - roaming
    00> I: [MODEM] PSM parameter update: TAU: 3240, Active time: -1
    00> I: [MODEM] client_id: nrf-35940*
    00> I: [AWS] iot_connect - init done
    00> W: [AWS] iot_reconnect - wait 30 s connect try: 1/30
    00> W: [AWS] IOT_EVT_CONNECTED
    00> I: [MODEM] BOOT Image Confirmed
    00> I: [MAIN] DL INIT
    00> D: state = 1
    00> I: Downloading: http://ul1.epaperframe.de/NDUmX2z.dl [0]
    00> [MAIN] Downloading http://ul1.epaperframe.de/NDUmX2z.dl
    00> D: Port not specified, using default: 80
    00> D: Failed to resolve hostname ul1.epaperframe.de on IPv6
    00> D: family: 1, type: 1, proto: 6
    00> I: Connecting to 3.5.134.246
    00> D: fd 1, addrlen 8, fam IPv4, port 80
    00> D: state = 2
    00> D: Receiving up to 2048 bytes at 0x2000cbd8...
    00> D: Read 620 bytes from socket
    00> D: GET header size: 620
    00> E: Unexpected HTTP response: 301 moved permanently
    00> [DL] Error -77 during download
    00> D: state = 4
    00> D: state = 0
    00> [DL] CLOSED
    00> D: Connection closed
    00> [DL] Payload: "http/1.1 301 moved permanently"

    The links are save to stay public But they wont work anymore after some time

    The Download Client Sample worked fine btw. so thats not the issue.

Children
No Data
Related