<?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: Files.download does not start when number of files in folder is &amp;gt; 1000 in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541733#M2119</link>
    <description>&lt;P&gt;TQ for your message and response.&lt;/P&gt;&lt;P&gt;Is there any way to get the a callback for then when the request is complete?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/10"&gt;@Greg-DB&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;You should update your code to only submit one (or a few) of these at a time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, you can use &lt;A href="http://dropbox.github.io/SwiftyDropbox/api-docs/latest/Classes/FilesRoutes.html#/s:13SwiftyDropbox11FilesRoutesC11downloadZip4path9overwrite11destinationAA19DownloadRequestFileCyAA0C0C0jF16ResultSerializerCAK0jf5ErrorN0CGSS_Sb10Foundation3URLVAS_So17NSHTTPURLResponseCtctF" target="_self"&gt;the downloadZip method&lt;/A&gt; to download an entire folder as a zip using one request.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What are the options (swift) to submit them one at a time? (That was actually one of my thinking but I've not been able to get this done as&lt;SPAN&gt;&lt;EM&gt; 'client.files.download'&lt;/EM&gt;&amp;nbsp;doesn't return a callback.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there a Response .success in the api?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I also tried to use&amp;nbsp;&lt;/SPAN&gt;dispatch group, entering just before calling&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt; 'client.files.download'&lt;/EM&gt; and&amp;nbsp;exiting after.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the suggestion to use downloadZip method, users are likely populating and removing files from their folders so this isn't much helpful.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank. you&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 28 Aug 2021 02:40:55 GMT</pubDate>
    <dc:creator>App4G</dc:creator>
    <dc:date>2021-08-28T02:40:55Z</dc:date>
    <item>
      <title>Files.download does not start when number of files in folder is &gt; 1000</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541663#M2115</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having trouble downloading entire folders to a local device via swiftyDropbox.&lt;/P&gt;
&lt;P&gt;I am doing the ListFolder and ListFolderContinue (which I observe that it chunks it to ~500 files per response) and appending it to a local array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After which, I pass this array to files.download. However, I am finding out that in cases where my folder is &amp;gt;1000 files (txt files ~0.5-1kb in size), the download process will not start.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;   static func downloadMissingFiles(client: DropboxClient, callingProcess: String) {
      let fileManager = FileManager.default
      let localBaseURL = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent("Cloud/Dropbox", isDirectory: true)
      
      // Data will be in the form of
      // key   : "/workouts/workout list 1/peye.mrc"
      // value : "//workouts/workout list 1/peye.mrc=_-_=015ca880b135d01000000020cb26de0"
      for dbFiles in Array(dbFileNameRevDict) {
        let dbFilePathLower = dbFiles.key
        let dbFileNameRev = dbFiles.value
        let fullURL = localBaseURL.appendingPathComponent(dbFileNameRev)
        
        if fileManager.fileExists(atPath: fullURL.path) {
          print("  -&amp;gt; FILE EXISTS dbFileNameRev:\(dbFileNameRev)")
          localFileList.append(dbFileNameRev)
        } else {
          let destination : (URL, HTTPURLResponse) -&amp;gt; URL = { temporaryURL, response in
            return fullURL
          }
          
          client.files.download(path:dbFilePathLower, overwrite: true, destination: destination)
            .response { response, error in
              if let (_, url) = response {
                print("====&amp;gt; DOWNLOADED:\(url.lastPathComponent)")
              } else if let error = error {
               print(error)
            }
            /// This gives a progress of every single file on it's own. Hence, useless
            // .progress { progressData in
            //  print(progressData)
            // }
        }
      }
    }
  }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried various method to download these files, I also tried to do a serial queue to iterate the array of files one by one but it doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how I process the ListFolder and ListFolderContinue, looking at the hasMore attribute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;          // https://stackoverflow.com/a/52870045/14414215
          if result.hasMore == true {
            processDBMore(client: client, cursor: result.cursor)
          } else {
            // When there is no more files (as indicated by hasMore == false)
            // start downloading the files
            downloadMissingFiles(client: client, callingProcess: "processDBMore-Finish")
            print("PrcessDBMore - dropboxGroup.leave")
            dropboxGroup.leave()
          }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I've been at this for 3 days already. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 09:03:24 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541663#M2115</guid>
      <dc:creator>App4G</dc:creator>
      <dc:date>2021-08-30T09:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Files.download does not start when number of files in folder is &gt; 1000</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541686#M2117</link>
      <description>&lt;P&gt;Each 'client.files.download' call downloads one file by making one HTTPS request to the Dropbox API servers. Additionally, these calls run asynchronously, and will not block until the call completes. That is, calling 'client.files.download' will start the HTTPS request, but will itself return before it's complete and the response is fully received. (It just runs the supplied block once the request is done.) That being the case, in the code you showed here, you're actually starting 1000 connections in a row, at almost the same time, so it's likely exhausting your network connection. You should update your code to only submit one (or a few) of these at a time. You mentioned you tried a serial queue, but that may be running in to the same issue, since the actual requests run asynchronously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can use &lt;A href="http://dropbox.github.io/SwiftyDropbox/api-docs/latest/Classes/FilesRoutes.html#/s:13SwiftyDropbox11FilesRoutesC11downloadZip4path9overwrite11destinationAA19DownloadRequestFileCyAA0C0C0jF16ResultSerializerCAK0jf5ErrorN0CGSS_Sb10Foundation3URLVAS_So17NSHTTPURLResponseCtctF" target="_self"&gt;the downloadZip method&lt;/A&gt; to download an entire folder as a zip using one request.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 18:16:16 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541686#M2117</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-08-27T18:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Files.download does not start when number of files in folder is &gt; 1000</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541733#M2119</link>
      <description>&lt;P&gt;TQ for your message and response.&lt;/P&gt;&lt;P&gt;Is there any way to get the a callback for then when the request is complete?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/10"&gt;@Greg-DB&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;You should update your code to only submit one (or a few) of these at a time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, you can use &lt;A href="http://dropbox.github.io/SwiftyDropbox/api-docs/latest/Classes/FilesRoutes.html#/s:13SwiftyDropbox11FilesRoutesC11downloadZip4path9overwrite11destinationAA19DownloadRequestFileCyAA0C0C0jF16ResultSerializerCAK0jf5ErrorN0CGSS_Sb10Foundation3URLVAS_So17NSHTTPURLResponseCtctF" target="_self"&gt;the downloadZip method&lt;/A&gt; to download an entire folder as a zip using one request.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What are the options (swift) to submit them one at a time? (That was actually one of my thinking but I've not been able to get this done as&lt;SPAN&gt;&lt;EM&gt; 'client.files.download'&lt;/EM&gt;&amp;nbsp;doesn't return a callback.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there a Response .success in the api?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I also tried to use&amp;nbsp;&lt;/SPAN&gt;dispatch group, entering just before calling&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt; 'client.files.download'&lt;/EM&gt; and&amp;nbsp;exiting after.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the suggestion to use downloadZip method, users are likely populating and removing files from their folders so this isn't much helpful.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank. you&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 02:40:55 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541733#M2119</guid>
      <dc:creator>App4G</dc:creator>
      <dc:date>2021-08-28T02:40:55Z</dc:date>
    </item>
    <item>
      <title>[SOLVED] Re: Files.download does not start when number of files in folder is &gt; 1000</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541750#M2120</link>
      <description>&lt;P&gt;This post&amp;nbsp;&lt;A href="https://stackoverflow.com/a/66227963/14414215" target="_blank" rel="noopener"&gt;https://stackoverflow.com/a/66227963/14414215&lt;/A&gt;&amp;nbsp;greatly helped in my understanding of how &lt;EM&gt;semaphore&lt;/EM&gt; works and how implementing semaphores (besides using dispatchGroups) is able to properly control the &lt;EM&gt;files.download &lt;/EM&gt;calls.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;   static func downloadMissingFiles(client: DropboxClient, callingProcess: String) {
      let fileManager = FileManager.default
      let localBaseURL = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent("Cloud/Dropbox", isDirectory: true)
      let semaphore = DispatchSemaphore(value: 1)  // insert desired concurrent downloads value here.

      // Data will be in the form of
      // key   : "/workouts/workout list 1/peye.mrc"
      // value : "//workouts/workout list 1/peye.mrc=_-_=015ca880b135d01000000020cb26de0"
      DispatchQueue.global().async { // Wrap the call within an async block
      for dbFiles in Array(dbFileNameRevDict) {
        semaphore.wait() // Decrement the semaphore counter
        let dbFilePathLower = dbFiles.key
        let dbFileNameRev = dbFiles.value
        let fullURL = localBaseURL.appendingPathComponent(dbFileNameRev)
        
        if fileManager.fileExists(atPath: fullURL.path) {
          print("  -&amp;gt; FILE EXISTS dbFileNameRev:\(dbFileNameRev)")
          localFileList.append(dbFileNameRev)
          semaphore.signal()  // Increment semaphore counter
        } else {
          let destination : (URL, HTTPURLResponse) -&amp;gt; URL = { temporaryURL, response in
            return fullURL
          }
          
          client.files.download(path:dbFilePathLower, overwrite: true, destination: destination)
            .response { response, error in
              if let (_, url) = response {
                print("====&amp;gt; DOWNLOADED:\(url.lastPathComponent)")
                // we've reached here means we've successfully download the file
                // So we can (release)increment semaphore counter
                semaphore.signal() 
              } else if let error = error {
               print(error)
            }
            /// This gives a progress of every single file on it's own. Hence, useless
            // .progress { progressData in
            //  print(progressData)
            // }
        }
      }
    }
   }
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 02:31:16 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Files-download-does-not-start-when-number-of-files-in-folder-is/m-p/541750#M2120</guid>
      <dc:creator>App4G</dc:creator>
      <dc:date>2021-08-29T02:31:16Z</dc:date>
    </item>
  </channel>
</rss>

