Ashish
Ashish

Reputation: 8529

How to use URL path as a file name to download?

I want to download these 2 app.zip files from a server:

https://tempapps.myserver.com/apps%2FNews%2Fapp.zip

https://tempapps.myserver.com/apps%2Fsports%2Fapp.zip

When I download these files with mozilla, it downloads them as apps_news_app.zip and apps_sports_app.zip.
I want to achieve the same in my program.

Upvotes: 3

Views: 1467

Answers (2)

cortices
cortices

Reputation: 373

If using java, you would use something like

String newUrl = "whatever the url is".replace("\%2F", "_");

Open http://doc.qt.io/qt-5/qstring.html and scroll to replace for info.

BTW, I am not sure about the backslash. If the above doesn't work, try different combinations of backslash or not before those argument strings.

Upvotes: 3

Palmik
Palmik

Reputation: 2665

To get normal-human readable url from percent-encoded one:

QString humanReadable = QUrl::fromPercentEncoded("https://example.com/something%20here.zip");

To get percent-encoded url:

QUrl myUrl("https://example.com/something here.zip");
QString percentEncoded = myUrl.encoded();

For more information, be sure to visit the QUrl documentation.

Upvotes: 5

Related Questions