Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uploading an image to FTP server #150

Open
MhmdRizk opened this issue Apr 25, 2019 · 0 comments
Open

uploading an image to FTP server #150

MhmdRizk opened this issue Apr 25, 2019 · 0 comments

Comments

@MhmdRizk
Copy link

Hello, thanks a lot for this useful library, I'm trying to upload an image to an ftp server, the file is being uploaded successfully but it's size is remaining zero KB, can anyone help me please.

`

var ftpProvider: FTPFileProvider?

override func viewDidLoad() {
               super.viewDidLoad()

               self.uploadPicker.delegate = self

               // information 
                let server: URL = URL(string: "ftp://xxx.xxx.xxx.xxx/")!
               let username = "xxxxx"
               let password = "xxxxxxx"
    
               let credential = URLCredential(user: username, password: password, persistence: .permanent)
    

               ftpProvider = FTPFileProvider(baseURL: server, mode: FTPFileProvider.Mode.passive, credential: credential, cache: URLCache())
    
               ftpProvider?.delegate = self
   
}
               //when image is picked 
               func imagePickerController(_ picker: UIImagePickerController,                                                                            
                didFinishPickingMediaWithInfo info: [String : Any]) {
    guard let chosenImage = info[UIImagePickerControllerOriginalImage] as? UIImage else{
        print("RIZK:- issue in picking images ")
        return
    }

     // save image file 
    _ = SavingManager.shared.saveImage(image: chosenImage)
  
    // get image url 
    guard let localURL = SavingManager.shared.getSavedImageURL("fileName.png") else{
        return
    }
   
    // check that image is not nil         
    guard  let imagePreview = SavingManager.shared.getSavedImage(named: "fileName.png")         else{
        return
    }
    
    // check image size 
    SavingManager.shared.getFileSize(localURL.path)
    
    print("RIZK:--- file name should be \(DataManager.shared.getArchivedUser()?.lastName ?? "Guest")-\(Int(Date().timeIntervalSince1970))")
 let imageName = "\(DataManager.shared.getArchivedUser()?.lastName ?? "Guest")-\(Int(Date().timeIntervalSince1970)).png"
    
  
    
    
    _ = ftpProvider?.copyItem(localFile: localURL, to: "files/\(imageName)", overwrite: true, completionHandler: { (error) in
        if error == nil {
            print("RIZK:-- Ready to upload")
        }else{
            print("RIZK:--\(error?.localizedDescription ?? "")")
        }
    })

    

    self.navigationController?.dismiss(animated:true, completion: nil)
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant