Why am i getting FirebaseStorage.StorageError error 8?

341 views Asked by At

When attempting to post with an image to Firebase Cloud I am getting "Cannot create post: This operation could not be completed. (FirebaseStorage.StorageError error 8)"

What could be the issue for this?

//
//  StorageFile.swift
//  Socialcademy
//
//  Created by Micahela  on 7/1/22.
//

import Foundation
import FirebaseStorage


struct StorageFile {
    private let storageReference: StorageReference
    
    func putFile(from fileURL: URL) async throws -> Self {
        _ = try await storageReference.putFileAsync(from: fileURL)
        return self
    }
    
    func getDownloadURL() async throws -> URL {
        return try await storageReference.downloadURL()
    }
    
    func delete() async throws {
        try await storageReference.delete()
    }
}

extension StorageFile {
    private static let storage = Storage.storage()
    
    static func with(namespace: String, identifier: String) -> StorageFile
    {
        let path = "\(namespace)/\(identifier)"
        let storageReference = storage.reference().child(path)
        return StorageFile(storageReference: storageReference)
    }

    
    static func atURL(_ downloadURL: URL) -> StorageFile {
        let storageReference = storage.reference(forURL: downloadURL.absoluteString)
        return StorageFile(storageReference: storageReference
        )
    }
}


1

There are 1 answers

0
steve gibson On

By default it appears that firebase storage is set to deny all.

Go into firebase, then storage and then select rules.

Change this: allow read, write: if false;

To This: allow read, write: if request.auth != null;

This will allow the logged in user to use FireBase Storage.