Download a GitHub Release
-
A release, not a raw file :/ Sorry, I wasn't detailed enough when writing the question.
-
@FluentCoding "Unfortunately, this doesn't work" - you should specify in what way it did not work. What did you try and what failed?
-
@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.
-
Can anyone help me? :/
-
Hi,
You should provide a minimal compilable example that shows what you are trying to achieve.
-
@SGaist Really? I mean, isn't it all self-explanatory what I've already told you?
-
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 ?
-
@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&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200605%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200605T192402Z&X-Amz-Expires=300&X-Amz-Signature=909b7333ee38223ea6f6f9f11d18a2860cc3e343d6de452a3aea8632bed8684d&X-Amz-SignedHeaders=host&actor_id=0&repo_id=150754152&response-content-disposition=attachment%3B%20filename%3DFM-v5.9-FINAL.zip&response-content-type=application%2Foctet-stream">redirected</a>.</body></html>
-
So you get a redirection. Take a look at QNetworkAccessManager::RedirectPolicy.
-
Alright, thank you so much! It works now!