Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Download a GitHub Release
QtWS25 Last Chance

Download a GitHub Release

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 724 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • FluentCodingF Offline
    FluentCodingF Offline
    FluentCoding
    wrote on last edited by FluentCoding
    #1

    Hey!

    I want to download a release from github via QNetworkReply. Unfortunately, this doesn't work and I even tried to set the User-Agent via setHeader(). I already used QNetworkReply and I already have done the OpenSSL setup and it even worked when I downloaded a test file from my own server.

    What can I do?

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #11

      So you get a redirection. Take a look at QNetworkAccessManager::RedirectPolicy.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • FluentCodingF FluentCoding

        Hey!

        I want to download a release from github via QNetworkReply. Unfortunately, this doesn't work and I even tried to set the User-Agent via setHeader(). I already used QNetworkReply and I already have done the OpenSSL setup and it even worked when I downloaded a test file from my own server.

        What can I do?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @FluentCoding What do you want to download?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • FluentCodingF Offline
          FluentCodingF Offline
          FluentCoding
          wrote on last edited by FluentCoding
          #3

          A release, not a raw file :/ Sorry, I wasn't detailed enough when writing the question.

          jsulmJ 1 Reply Last reply
          0
          • FluentCodingF FluentCoding

            A release, not a raw file :/ Sorry, I wasn't detailed enough when writing the question.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @FluentCoding "Unfortunately, this doesn't work" - you should specify in what way it did not work. What did you try and what failed?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • FluentCodingF Offline
              FluentCodingF Offline
              FluentCoding
              wrote on last edited by
              #5

              @jsulm I have tried to download a release in form of a zip file (my file downloader class works - ive already tested it with another files) - the url looks like this: https://github.com/creator/repo/releases/download/version/file.zip. Passing this url to the get method of the QNetworkReply didn't help out so I tried to set a custom user agent header I found on the internet:

              request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader,
                                    "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1");
              

              ... but that didn't work out either. Now I'm confused cuz I don't see a way how to do it.

              1 Reply Last reply
              0
              • FluentCodingF Offline
                FluentCodingF Offline
                FluentCoding
                wrote on last edited by
                #6

                Can anyone help me? :/

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  Hi,

                  You should provide a minimal compilable example that shows what you are trying to achieve.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • FluentCodingF Offline
                    FluentCodingF Offline
                    FluentCoding
                    wrote on last edited by
                    #8

                    @SGaist Really? I mean, isn't it all self-explanatory what I've already told you?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      You expect me to come up with some code based on your explanations to find what you are doing wrong rather than you taking the time to provide a stripped down version of the code you already use so all the people here can test it and find what is going on ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • FluentCodingF Offline
                        FluentCodingF Offline
                        FluentCoding
                        wrote on last edited by
                        #10

                        @SGaist Alright. I'll send some code that explains my problem:

                        FileDownloader.h:

                        #ifndef FILEDOWNLOADER_H
                        #define FILEDOWNLOADER_H
                        
                        #include <QObject>
                        #include <QByteArray>
                        #include <QNetworkAccessManager>
                        #include <QNetworkRequest>
                        #include <QNetworkReply>
                        
                        class FileDownloader : public QObject
                        {
                         Q_OBJECT
                        public:
                            explicit FileDownloader(QUrl url, QObject *parent = 0);
                            virtual ~FileDownloader();
                            QByteArray downloadedData() const;
                        
                        signals:
                            void downloaded();
                            void progress(qint64 bytesReceived, qint64 bytesTotal);
                            void failed();
                        
                        private slots:
                            void fileDownloaded(QNetworkReply* pReply);
                            void fileProceed(qint64 bytesReceived, qint64 bytesTotal);
                        
                        private:
                            QNetworkAccessManager m_WebCtrl;
                            QByteArray m_DownloadedData;
                        };
                        
                        #endif // FILEDOWNLOADER_H
                        

                        FileDownloader.cpp:

                        #include "filedownloader.h"
                        
                        FileDownloader::FileDownloader(QUrl url, QObject *parent) :
                         QObject(parent)
                        {
                            QNetworkRequest request(url);
                            QNetworkReply* reply = m_WebCtrl.get(request);
                        
                            connect(reply, &QNetworkReply::downloadProgress, this, &FileDownloader::fileProceed);
                            connect(&m_WebCtrl, SIGNAL (finished(QNetworkReply*)), SLOT (fileDownloaded(QNetworkReply*)));
                        }
                        
                        FileDownloader::~FileDownloader(){}
                        
                        void FileDownloader::fileProceed(qint64 bytesReceived, qint64 bytesMax) {
                            emit progress(bytesReceived, bytesMax);
                        }
                        
                        void FileDownloader::fileDownloaded(QNetworkReply* pReply)
                        {
                            if (pReply->error()) {
                                emit failed();
                                return;
                            }
                            m_DownloadedData = pReply->readAll();
                        
                            pReply->deleteLater();
                            emit downloaded();
                        }
                        
                        QByteArray FileDownloader::downloadedData() const
                        {
                            return m_DownloadedData;
                        }
                        
                        

                        Snippet of my main class:

                        auto* downloader = new FileDownloader{"https://github.com/project-slippi/Ishiiruka/releases/download/r18/FM-v5.9-Slippi-r18-Win.zip", this};
                        
                        connect(downloader, &FileDownloader::downloaded, [this, downloader, progress](){
                                    delete progress;
                        
                                    QMessageBox::information(this, "File Downloaded!", "Your dolphin build has been downloaded!");
                        
                                    QSaveFile file;
                                    file.setFileName("C:/Users/fluentcoding/Desktop/test.zip");
                        
                                    if (!file.open(QIODevice::WriteOnly)) {
                                        return false;
                                    }
                        
                                    file.write(downloader->downloadedData());
                                    file.commit();
                        
                                    // START EXTRACTING ...
                                    downloader->deleteLater();
                                });
                        

                        And it basically downloads nothing - an archive that basically has this content (just found this out rn:):

                        <html><body>You are being <a href="https://github-production-release-asset-2e65be.s3.amazonaws.com/150754152/31122a80-c30f-11e8-944b-c4b3926ee588?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200605%2Fus-east-1%2Fs3%2Faws4_request&amp;X-Amz-Date=20200605T192402Z&amp;X-Amz-Expires=300&amp;X-Amz-Signature=909b7333ee38223ea6f6f9f11d18a2860cc3e343d6de452a3aea8632bed8684d&amp;X-Amz-SignedHeaders=host&amp;actor_id=0&amp;repo_id=150754152&amp;response-content-disposition=attachment%3B%20filename%3DFM-v5.9-FINAL.zip&amp;response-content-type=application%2Foctet-stream">redirected</a>.</body></html>
                        
                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          So you get a redirection. Take a look at QNetworkAccessManager::RedirectPolicy.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          3
                          • FluentCodingF Offline
                            FluentCodingF Offline
                            FluentCoding
                            wrote on last edited by
                            #12

                            Alright, thank you so much! It works now!

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved