Get filename from url

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Falcon

Hi guys,i have some trouble:
I have some url like this https://someurl/somesome/Eib387h3ox8b2
and i wanna know the name of the file on that url.
Intput url=https://someurl/somesome/Eib387h3ox8b2
Output ‘test.txt’

How can i do that?

Thanks.

I’m not sure what you’re trying to do. What is the url pointing to? A webpage?

MrEliptik | 2021-03-22 22:05

To me, it looks like in the general way you’re posing the question, that’s impossible. unless the Eib387h3ox8b2 at the end of the URL encodes the “test.txt” name, but if it does, I wouldn’t begin to know what decoder to use. It isn’t coded in hex digits and it doesn’t seem to be base64.

URLs may point to files that sit on a webserver, and these files have names on the webserver, but you can’t get the the name of that file - all you have to go on is the URL. If the name isn’t in the URL, in general, you’re stuck. Your web server may send you the name of the file in a HTTP Header, or it might provide an API to get at the filename, but if all you have is some random URL, then no, you can’t get the name of the file that is refered to by that URL.

archeron | 2021-03-23 01:09

Thanks for fast reply!
The url is pointing to some file like “test.txt”

Falcon | 2021-03-23 05:08

Thanks for fast reply!

I have some file on pcloud.com(something like Google drive),I am very new to
HTTPRequest and don’t know how to ask to pcloud to get the name of the file what the url is pointing to.
If it’s impossible then i have an another questions:
I have some serverIp and serverPort (they are variables in my client.gd (192.67.45.140,5075) ) -the address of the server to which the client need to be connected.Lets assume that I changed my server from (192.67.45.140,5075) to (192.45.67.147,5075),how can i tell the clients the new server’s address?

Falcon | 2021-03-23 05:22

:bust_in_silhouette: Reply From: Falcon

Sorry for this stupid question,I have solved it by
http post request to ‘https://eapi.pcloud.com/getpublinkdownload

:bust_in_silhouette: Reply From: archeron

This isn’t really a Godot-specific question, it’s a question on how to use PCloud.com’s API. They seem to have an API that’s documented at https://docs.pcloud.com/, so start reading there.

If you need help with how to interface with the API using HTTPRequests, my suggestion would be to download their SDK package for one of the languages you feel comfortable in (they don’t seem to have a Python implementation of their SDK, which is a shame, because it would syntactically be closest go GDScript) and look at how their SDK code does the interfacing.

If you need people to help you, you will have much more success asking other PCloud.com users or even PCloud.com’s support staff.

Chances are what you want to achieve will be fairly easy, even if you have to write your own interface code in GDScript.