Idan Aviv Idan Aviv - 1 year ago 408
Swift Question

Firebase store: trying to store to local file gives an error

When I try to store a file from the Firebase storage following the example from the documents I received the following error:

Optional(Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object=ProfilePicture/Jf2dFzI7LZNzQkOkdFfa3UWQJyH2.jpg,, NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=NSCocoaErrorDomain, NSFilePath=/local/images, NSUnderlyingError=0x7fc8a080ab50 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}, ResponseErrorCode=513})

Here is my code:

let storage =
let storageRef = storage.referenceForURL("gs://")

let islandRef = storageRef.child("ProfilePicture/"+uid+".jpg")
// Create local filesystem URL
let localURL: NSURL! = NSURL(string: "file:///local/images/island.jpg")

// Download to the local filesystem
let downloadTask = islandRef.writeToFile(localURL) { (URL, error) -> Void in
if (error != nil) {
} else {
let data = NSData(contentsOfURL: URL!)
self.profileImage.image = UIImage(data: data!)

Answer Source

The issue here is that you're getting an NSPOSIXErrorDomain error indicating that you don't have permission to write to the file file:///local/tumbnails/\(imageName), presumably because that directory (/local) doesn't exist and even if it does, you don't have permission to write to it.

I'd take a look at docs for a list of directories you can write to--you should probably be using /Documents or /tmp for this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download