Idan Aviv
Idan Aviv

Reputation: 1293

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, bucket=mapit-1333.appspot.com, 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 = FIRStorage.storage()
       let storageRef = storage.referenceForURL("gs://mapit-1333.appspot.com")


       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) {
                print(error)
            } else {
                let data = NSData(contentsOfURL: URL!)
                self.profileImage.image = UIImage(data: data!)
            }
        }

Upvotes: 3

Views: 1119

Answers (1)

Mtoklitz113
Mtoklitz113

Reputation: 3878

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/images/\(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.

Upvotes: 2

Related Questions