Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value of type 'GTLDriveFile' has no member 'downloadUrl'

I am following this tutorial and I'm trying to do it in Swift.

The file object does not have a downloadUrl property and I do not understand why. I checked the API and it says that this property exists, at least for Objective-C. But all other properties exist for Swift, so why not downloadUrl?

I do a simple thing like:

let file: GTLDriveFile!
file.downloadUrl

and downloadUrl get underlined in red with the error: Value of type 'GTLDriveFile' has no member 'downloadUrl'.

Here is my code:

private let service = GTLServiceDrive()

// Parse results and display
func displayResultWithTicket(ticket : GTLServiceTicket,
    finishedWithObject response : GTLDriveFileList,
    error : NSError?) {

        if let error = error {
            showAlert("Error", message: error.localizedDescription)
            return
        }

        var filesString = ""

        if let files = response.files where !files.isEmpty {
            filesString += "Files:\n"

            for file in files as! [GTLDriveFile] {
                var fetcher: GTMSessionFetcher = service.fetcherService.fetcherWithURL(file.downloadUrl)
                filesString += "\(file.name)\n"
            }
        } else {
            filesString = "No files found."
        }

        output.text = filesString
}
like image 576
magohamoth Avatar asked Dec 01 '25 00:12

magohamoth


1 Answers

What I ended up doing is generating the download URL myself like this:

let url = "https://www.googleapis.com/drive/v2/files/" + file.identifier + "?alt=media"
let fetcher = service.fetcherService.fetcherWithURLString(url)
fetcher.beginFetchWithCompletionHandler({ (data, error) -> Void in
    if error == nil {
        print(data)
    } else {
        print("An error occurred: " + error!.localizedDescription)
    }
})

Another option is to call without "?alt=media" and extract downloadUrl from the meta data json

like image 162
david72 Avatar answered Dec 02 '25 14:12

david72



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!