constantine-fry / rebekka

Rebekka - FTP/FTPS client in Swift.
BSD 2-Clause "Simplified" License
87 stars 56 forks source link

Uploading Image from Photo Gallery #8

Closed MuneebSaeed4 closed 7 years ago

MuneebSaeed4 commented 8 years ago

There is a problem while uploading Image from Gallery.

let URL = NSBundle.mainBundle().pathForResource("TestUplaod", ofType: "png", inDirectory: "\(getImagePath)")

Always returning nil I saved an image in Directory "getImagePath"

I tried to give direct path of image but error still exists.. also tried "URLForResource" but no use. Kindlly resolve my issue please. P.S i am trying on Simulator

alexviquez commented 8 years ago

Hello!, i found this solution http://stackoverflow.com/questions/34335867/upload-file-to-ftp-server-with-swift use this code to solve your problem

let file = "myFile.txt" if let dir : NSString = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true).first { //path will be stored here let sPath = dir.stringByAppendingPathComponent(file); print(sPath) // printing the file path

let url: NSURL = NSURL(string: sPath)!

let destinationFile = "myFile.txt" FTPSession.upload(url, path: destinationFile) { // <-- Dies here (result, error) -> Void in print("- Result:\n\(result), error: \(error)\n\n") } }

All credits to O-mkar

constantine-fry commented 7 years ago

I will close the issue since it's old and seems to be resolved.