I have successfully saved the audio file to Parse, but I am trying to upload it again. I cannot decide what the block should do with getDataInBackgroundWithBlock. And how to actually save the file. Any help is much appreciated!
let query = PFQuery(className: "wordRecordings")
query.whereKey("wordName", equalTo: "\(joinedWord)")
query.findObjectsInBackgroundWithBlock { (objects:[PFObject]?, error:NSError?) -> Void in
if error == nil{
for object in objects! {
let audioFile = object["audioFile"] as! PFFile
audioFile.getDataInBackgroundWithBlock{ (audioFile: NSData, error:NSError?) -> Void in
if error == nil {
let audioFile = AudioFile(data: audioFile)
}
}
}
} else {
print("Error: \(error!) \(error!.userInfo)")
}
}
Thanks to @David below is a working solution with path code.
let fileString = "\(fileName)"
let documentsDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let path = documentsDirectory.URLByAppendingPathComponent(fileString)
audioFile.getDataInBackgroundWithBlock { (audioFile:NSData?, error:NSError?) -> Void in
if error == nil {
audioFile.writeToURL(path, atomically: true)
} else {
print("error with getData")
}
}
richc source
share