Any help would be appreciated, I have obviously looked over the API and tried a few examples of getting file upload to work, and I have gotten the asynchronous method to work, however I need to use the Synchronous method for my app. When I looked at the API for the synchronous method all was well, but when I tried to implement it i got errors in xCode.
Error: Expected member name following ‘.’
Edit: Line 1 is where the error in xCode occurs
Code:
Types.try({ () -> Void in
var data = NSData(bytes:"Hello mbaas!\nUploading files is easy!", length:37)
var uploadedFile = self.backendless.fileService.upload("myfiles/myhelloworld-sync.txt", content: data)
print("File has been uploaded. File URL is - \(uploadedFile.fileURL)") },
catch: { (exception) -> Void in
print("Server reported an error: \(exception as Fault)")
} )
If anyone has gotten synchronous file uploading to work, it would be greatly appreciated if you could show me a working example. Thank you.
Hi Joey,
Use ‘saveFile:’ method of FileService class instead ‘upload’.
I just checked both sync & async methods:
func createFileSync() {
Types.tryblock({ () -> Void in
let bytes = "The quick brown fox jumps over the lazy dog".dataUsingEncoding(NSUTF8StringEncoding)
let savedFile = self.backendless.file.saveFile("/doc/sync.txt", content:bytes, overwriteIfExist:true)
print("File has been saved: \(savedFile.fileURL)")
},
catchblock: { (exception) -> Void in
print("Server reported an error: \(exception as! Fault)")
}
)
}
func createFileAsync() {
let bytes = "The quick brown fox jumps over the lazy dog".dataUsingEncoding(NSUTF8StringEncoding)
backendless.file.saveFile("/doc/async.txt", content:bytes, overwriteIfExist:true,
response: { ( savedFile : BackendlessFile!) -> () in
print("File has been saved: \(savedFile.fileURL)")
},
error: { ( fault : Fault!) -> () in
print("Server reported an error: \(fault)")
}
)
}
and they works fine for me, here is app log:
http://support.backendless.com/public/attachments/40d377c99d421fe42dc232835024f536.png</img>
and result on backendless app dashboard:
http://support.backendless.com/public/attachments/73f9affed9655b5e4d5e5ef86b872591.png</img>
I use XCode 7.3, iPhone 5s & latest Backendless SDK.
Regards,
Slava