FileProvider icon indicating copy to clipboard operation
FileProvider copied to clipboard

Any way to follow the upload's progress ?

Open xavierburzig opened this issue 6 years ago • 1 comments
trafficstars

Hi everybody,

I'm currently using your FileProvider to write files in a non-secure FTP server and I actually got a working code

let filename = "test.txt" print("Test started:.") let data = "Hello world".data(using: .ascii) self.documentsProvider?.writeContents(path: self.ftpPathPhotos + "/" + filename, contents: data, overwrite: true) { (error) in if let theError = error { print("error = \(theError)") } else { print("alllllllright") } }

Question is : I was wondering if there is any way to follow the upload's progression, cause I saw in your source repo that you've got something close but I can't figure it out ?

In advance cheers and have a great day

Xavier

xavierburzig avatar Oct 25 '19 14:10 xavierburzig

Hi,

You need the provider's delegate. Example:

import FilesProvider

class WhatEver: UIViewController or Whatever, FileProviderDelegate {
  // Here you have your stuff
  // The important thing is to implement 'FileProviderDelegate'
  // Then in code you will create the object using something like:
  documentsProvider = FTPFileProvider(baseURL: your_url, mode: .your_mode, credential: your_credentials, cache: .your_cache_manage)
  // After that, do:
  documentsProvider.delegate = self // This will delegate some FilesProvider function to this class

  // You will need to add the following stubs from the 'FileProviderDelegate'
  func fileproviderSucceed(_ fileProvider: FileProviderOperations, operation: FileOperationType) {
    // Called when transaction finish successfully
  }

  func fileproviderFailed(_ fileProvider: FileProviderOperations, operation: FileOperationType, error: Error) {
    // Called when there's some kind of error in the transaction
  }
  
  func fileproviderProgress(_ fileProvider: FileProviderOperations, operation: FileOperationType, progress: Float) {
    // This is the one you want. Called with the progress. It is a float that goes from 0.0 to 1.0
  }

}

With that delegate you will be able to manage the progress of the transactions. Upload and download.

raaowx avatar Jun 04 '20 07:06 raaowx