I'm trying to upload an image to a FTP server using swift 4
I used FileProvider which is a library for Ftp connection iOS
anyway I'm checking the provider is reachable. and Im getting this error
The operation couldn’t be completed. (NSURLErrorDomain error -1011.)
this is the full error object:
Error Domain=NSURLErrorDomain Code=-1011 "(null)" UserInfo={NSErrorFailingURLKey=ftp://xxxx.xxxx.xxxx.xxxx:21/, NSErrorFailingURLStringKey=ftp://xxxx.xxxx.xxxx.xxxx:21/, NSURL=ftp://xxxx.xxxx.xxxx.xxxx:21/}
this is my code:
self.ftpProvider!.isReachable { (flag, error) in
if flag {
print("RIZK:--- provider is reachable ")
let progress = self.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 ?? "")")
}
})
print(progress?.fractionCompleted ?? 0)
}else{
print("RIZK:--- provider not reachable, with error \(error?.localizedDescription ?? "") ")
}
}
Related
I'm trying to send data to Cloud Storage using the Firebase SDK for iOS. In doing so I'm creating a reference (StorageReference) in this way:
let storageRef = Storage.storage().reference(forURL: Config.CONFIG_ROOF_REF).child("Posts").child(videoIDString)
And using the putFile method:
storageRef.putFile(from: videoURL, metadata: nil) { (metadata, error) in
if error != nil{
ProgressHUD.showError(error?.localizedDescription)
return
}
storageRef.downloadURL(completion: { (url, error) in
if error != nil {
return
}else {
self.videourl = url?.absoluteString
onSuccess(videourl!)
}
})
}
I pass in the argument videoURL and I receive back the error:
An unknown error occurred, please check the server response
I cannot understand why I receive that error since the videoURL I'm passing seems legit.
The videoURL I'm passing is this one:
file:///Users/andreagualandris/Library/Developer/CoreSimulator/Devices/7D3329AC-AD8D-4553-AC61-FDF8435134B6/data/Containers/Data/PluginKitPlugin/8229E521-A7A2-4C09-8312-CC6106C2FED8/tmp/trim.7CC60B3A-6982-4F42-AA63-ED094288A562.MOV
So I think this is a normal URL and there shouldn't be any problem with it.
The actual server response on the console is :
2020-01-26 10:31:27.107215+0100 InstagramClone[2517:235684] Task <4AC8F3F2-1CC6-4064-BBF7-6D0375769C9A>.<1> finished with error [-1] Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo={NSErrorFailingURLStringKey=https://firebasestorage.googleapis.com/v0/b/instagramclone-1ed36.appspot.com/o/Posts%2F412BA396-6CAD-4197-817F-1AA0D9E6E6FE?uploadType=resumable&name=Posts%2F412BA396-6CAD-4197-817F-1AA0D9E6E6FE&upload_id=AEnB2UoAHEWQ0WDv_Id2TK_xSL_71Jrj8kbmuDfLpGkO8fBe6e9sBF74QUj5r0MLdltJN79z5fWAtoqOx8JSAfpppyPe6qKrxA&upload_protocol=resumable, NSErrorFailingURLKey=https://firebasestorage.googleapis.com/v0/b/instagramclone-1ed36.appspot.com/o/Posts%2F412BA396-6CAD-4197-817F-1AA0D9E6E6FE?uploadType=resumable&name=Posts%2F412BA396-6CAD-4197-817F-1AA0D9E6E6FE&upload_id=AEnB2UoAHEWQ0WDv_Id2TK_xSL_71Jrj8kbmuDfLpGkO8fBe6e9sBF74QUj5r0MLdltJN79z5fWAtoqOx8JSAfpppyPe6qKrxA&upload_protocol=resumable, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"BackgroundUploadTask <4AC8F3F2-1CC6-4064-BBF7-6D0375769C9A>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <4AC8F3F2-1CC6-4064-BBF7-6D0375769C9A>.<1>, NSLocalizedDescription=unknown error}
Using the below code to check if the user's library contains a particular song. It returns an error. What could I be doing wrong? I couldn't find examples for this particular 'forCheckingIfSavedTracksContains' method anywhere.
let accessToken = SPTAuth.defaultInstance().sessionUserDefaultsKey
let request: URLRequest = try!
SPTYourMusic.createRequest(forCheckingIfSavedTracksContains: ["spotify:track:3ZakaL0QEt5eeD3N7HbaN1"], forUserWithAccessToken: accessToken)
SPTRequest.sharedHandler().perform(request) { (error, response, data) in
if error == nil {
print ("this is data\(String(describing: data))")
} else {
print ("error")
}
}
The error is:
Error Domain=NSURLErrorDomain Code=-1012 "(null)" UserInfo={NSErrorFailingURLStringKey=api.spotify.com/v1/me/tracks/contains?ids=, NSUnderlyingError=0x109e7eb60 {Error Domain=kCFErrorDomainCFNetwork Code=-1012 "(null)" UserInfo={_kCFURLErrorAuthFailedResponseKey=<CFURLResponse 0x109e7e970 [0x1b441e538]>{url = api.spotify.com/v1/me/tracks/contains?ids=}}}, NSErrorFailingURLKey=api.spotify.com/v1/me/tracks/contains?ids=}
I'm trying to rename a file (a FileWrapper containing a UIDocument subclass) as follows:
coordinationQueue.async {
var error: NSError? = nil
let fileCoordinator = NSFileCoordinator(filePresenter: self)
fileCoordinator.coordinate(readingItemAt: url, options: .withoutChanges,
writingItemAt: targetURL, options: .forMoving, error: &error) { fromURL, toURL in
do {
fileCoordinator.item(at: fromURL, willMoveTo: toURL)
try FileManager().moveItem(at: fromURL, to: toURL)
fileCoordinator.item(at: fromURL, didMoveTo: toURL)
// Success!
} catch {
// Handle error
}
}
if let error = error {
// Handle error
}
}
… but it's failing on the moveItem, with the following error:
Error Domain=NSCocoaErrorDomain Code=513 "“from_file” couldn’t be moved because you don’t have permission to access “My_folder”." UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/My_folder/from_file, NSUserStringVariant=(
Move
), NSDestinationFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/My_folder/to_file, NSFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/My_folder/from_file, NSUnderlyingError=0x1c1240ab0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
Interestingly, it works on fine on the simulator.
Can anybody help me out with this? (x-posted on Apple forums)
So I'm trying to get FB and Twitter to respond from tappin on a table cell:
I set up the plist:
Then I created this function:
func schemeAvailable(scheme: String) -> Bool {
if let url = URL(string: scheme) {
return UIApplication.shared.canOpenURL(url)
}
return false
}
Then I tried to use it:
print(UIApplication.shared.canOpenURL(URL(string: "fb:")!))
if(schemeAvailable(scheme: "fb://")){
print("facebook agailable")
}
if(schemeAvailable(scheme: "twitter://")){
print("twitter agailable")
}
and get back a response of:
2016-10-03 17:04:09.096 JSONTesting[73245:2492124] -canOpenURL: failed for URL: "fb:" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
false
2016-10-03 17:04:09.097 JSONTesting[73245:2492124] -canOpenURL: failed for URL: "fb://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
2016-10-03 17:04:09.098 JSONTesting[73245:2492124] -canOpenURL: failed for URL: "twitter://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
I've tried with and without the // in the string but to no avail...get the same error back every time.
Thanks
I am sending some ios file data via an email contained in a plist. No issues attaching it, I can check the file and the contents. It's all there and I can open it as a plist. Clicking on it (I have associated it with my app) it opens and I get a valid path:
file:///private/var/mobile/Containers/Data/Application/C5454580-2BEB-4515-9BDE-FED85FF54F76/Documents/Inbox/ShareStrength-11.bps
that I pass but when I try and read back the NSDictionary (plist) I get nil content.
let sourceFile = NSDictionary(contentsOfFile: URLString)
Any ideas on what is going wrong. Having difficulty debugging.
EDIT: I found some error code:
var error: NSError?
let content = NSString(contentsOfFile: URLString, encoding:NSUTF8StringEncoding, error: &error)
if content != nil
{
println("content: \(content)")
}
else
{
println("error: \(error)")
}
And I get the error:
error: Optional(Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x17eceeb0 {NSFilePath=file:///private/var/mobile/Containers/Data/Application/571DB0FF-6C5A-4BEB-9FA8-6E4DFE10E850/Documents/Inbox/ShareStrength-13.bps, NSUnderlyingError=0x17ee9810 "The operation couldn’t be completed. No such file or directory"})
Is this a sandbox issue? How can I copy the attachment being passed as a URL?
I was using:
let URLString: String = url.absoluteString!
instead of:
let URLString: String = url.path!
Hope this helps someone else