How to create a QueryString in Swift that uses a wild card?

Hi,

I am trying to query a webserver for a Users Profile image. I do not know the filename of the image that the user uploads or the file type. What I do know is that a folder is created based on the users id and I have this id.

Additionally, Three files are generated from the uploaded file:

filename_l.extension // _l for large
filename_s.extension // _s for small
filename_xs.extension // extra small

How can I create a query string in Swift that will return any one of these files?

Thanks!

Hi @mmuldoon,
These are the bits in Swift that are fun …

enum FileSize: String {
    case small = "s"
    case large = "l"
    case extraSmall = "xs"
    
    func getQueryString(for filename: String, ext: String, url: String) -> String {
        return "\(url)\(filename)_\(self.rawValue).\(ext)"
    }
}

Now you can simply get the query string as

let f = FileSize.large
print(f.getQueryString(for: “filename”, ext:“txt”, url:“https://www.myserver.com/uploads/files/”))

Modify as you deem appropriate to your situation

cheers,

Jayant