<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Downloading a file, getting error in DropboxTransportClient.swift, line 200 in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Downloading-a-file-getting-error-in-DropboxTransportClient-swift/m-p/377849#M840</link>
    <description>&lt;P&gt;It looks like the issue is that the SDK expects a 'response' handler on the 'files.download' call, but you're not supplying one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll ask the team to fix this up to fail gracefully in this case, but as a workaround (and as a best practice in general), you should add a 'response' handler, e.g., as shown here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/dropbox/SwiftyDropbox#download-style-request" target="_blank"&gt;https://github.com/dropbox/SwiftyDropbox#download-style-request&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Also, I&amp;nbsp;recommend doing so for all of your calls so you can add some error handling. Otherwise, you won't know if/why a call failed.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Nov 2019 18:32:34 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2019-11-11T18:32:34Z</dc:date>
    <item>
      <title>Downloading a file, getting error in DropboxTransportClient.swift, line 200</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Downloading-a-file-getting-error-in-DropboxTransportClient-swift/m-p/377568#M839</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I've checked the forum and didn't find an answer.&lt;/P&gt;
&lt;P&gt;Overview: my app works with a SQLite db. I have an option to store the DB in DropBox (only store it, not working on it).&lt;/P&gt;
&lt;P&gt;The user download the DB, I create a file "device name".usr to say to other users the DB is in use right now.&lt;/P&gt;
&lt;P&gt;I've created this procedure (sorry, comments are in Italian):&lt;/P&gt;
&lt;PRE&gt;    func copiaDB() {
        let databaseURL = try! FileManager.default
            .url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
        .appendingPathComponent("db.sqlite")
        let completeUrl = URL(fileURLWithPath: databaseURL.path)
        let destination: (URL, HTTPURLResponse) -&amp;gt; URL = { temporaryURL, response in
                return completeUrl
        }
        
        let semo = DispatchSemaphore.init(value: 0)
        let downQueue = OperationQueue.init()
        downQueue.maxConcurrentOperationCount = 1
        // operation 1
        downQueue.addOperation {

            // detach database o errore sqlite
                dbQueue = try? AppDatabase.openDatabase(atPath: "")
                // copio file
            self.client?.files.download(path: "/db.sqlite", overwrite: true, destination: destination)
        }
        // operation 2
        downQueue.addOperation {
            // avverto che qualcuno sta lavorando sul file
            
            let fileData = "Database in uso".data(using: String.Encoding.utf8, allowLossyConversion: false)!

            self.client?.files.upload(path: "/\(UIDevice.current.name).usr", input: fileData)
        }
        // operation 3
        downQueue.addOperation {
            semo.wait()
            dbQueue = try? AppDatabase.openDatabase(atPath: databaseURL.path)
        }
    }&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;It work's fine, detach the DB, download it, create the usr file, attach the DB to queue so I can work on it locally.&lt;/P&gt;
&lt;P&gt;Here there is a little problem, not reguaridng DropBox. I need a way to advise user the download is completed, but i can't create an alert or change a label text because the download is async with the main queue.&lt;/P&gt;
&lt;P&gt;I need the procedure to work with OperationQueue because&lt;/P&gt;
&lt;PRE&gt;dbQueue = try? AppDatabase.openDatabase(atPath: databaseURL.path)&lt;/PRE&gt;
&lt;P&gt;needs to be exeguted after the download is finished, or i risk to compromise the db.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I created the procedure to check if the db is available in DropBox:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;    func checkDB() {
        
        client?.files.search(path: "", query: ".usr", mode: .filename).response {
            response, error in
            if let response = response {
                if response.matches.count == 0 {
                    self.copiaDB()
                } else {
                    self.inUso(tipo: (response.matches.first?.metadata.name)!)
                }
            } else if let _ = error {
                
            }
        }
    }&lt;/PRE&gt;
&lt;P&gt;self.inUso simply create an alert saying the device name is using the DB. This works, but, calling the first procedure copiaDB() I now got this error:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file /Users/marcopirola/Desktop/Progetto Swift/Gestione Affitti/SwiftyDropbox/Source/SwiftyDropbox/Shared/Handwritten/DropboxTransportClient.swift, line 200&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;2019-11-10 11:10:02.238294+0100 Gestione Affitti[11658:6548246] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file /Users/marcopirola/Desktop/Progetto Swift/Gestione Affitti/SwiftyDropbox/Source/SwiftyDropbox/Shared/Handwritten/DropboxTransportClient.swift, line 200&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;I&gt;&amp;nbsp;&lt;/I&gt;I tried to debug it, it actually download the db and create the .usr file, but then somehow it recalls the download procedure with a nil command string.&lt;/P&gt;
&lt;P&gt;I removed checkDB() from the procedure calling directly copiaDB() and it works again. Any idea?&lt;/P&gt;
&lt;P&gt;Thanks, Marco "Chetral" Pirola&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 18:43:27 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Downloading-a-file-getting-error-in-DropboxTransportClient-swift/m-p/377568#M839</guid>
      <dc:creator>Chetral</dc:creator>
      <dc:date>2019-11-11T18:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Downloading a file, getting error in DropboxTransportClient.swift, line 200</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Downloading-a-file-getting-error-in-DropboxTransportClient-swift/m-p/377849#M840</link>
      <description>&lt;P&gt;It looks like the issue is that the SDK expects a 'response' handler on the 'files.download' call, but you're not supplying one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll ask the team to fix this up to fail gracefully in this case, but as a workaround (and as a best practice in general), you should add a 'response' handler, e.g., as shown here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/dropbox/SwiftyDropbox#download-style-request" target="_blank"&gt;https://github.com/dropbox/SwiftyDropbox#download-style-request&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Also, I&amp;nbsp;recommend doing so for all of your calls so you can add some error handling. Otherwise, you won't know if/why a call failed.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 18:32:34 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Downloading-a-file-getting-error-in-DropboxTransportClient-swift/m-p/377849#M840</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-11-11T18:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Downloading a file, getting error in DropboxTransportClient.swift, line 200</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Downloading-a-file-getting-error-in-DropboxTransportClient-swift/m-p/377871#M841</link>
      <description>&lt;P&gt;Thanks Greg, I added response and error handling and now it works again!!!&lt;/P&gt;&lt;P&gt;You're the best &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@41457EF40051AFF130FDBFE21B496926/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Marco "Chetral" Pirola&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 20:03:07 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Downloading-a-file-getting-error-in-DropboxTransportClient-swift/m-p/377871#M841</guid>
      <dc:creator>Chetral</dc:creator>
      <dc:date>2019-11-11T20:03:07Z</dc:date>
    </item>
  </channel>
</rss>

