You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Firebase存储删除文件夹后无法上传文件问题求助

Fixing Firebase Storage Upload Error (-13000) After Clearing Storage

Let's tackle this upload issue head-on. The error you're seeing (FIRStorageErrorDomain Code=-13000 paired with NSURLErrorDomain) usually points to a problem with your file path, permissions, or how you're referencing your storage bucket. Here's what to check and fix:

1. Your Filename Is Likely the Culprit

The biggest red flag here is using videoURL.absoluteString as your filename. That string includes full path details like file:/private/var/mobile/... which has invalid characters and formatting for Firebase Storage paths. Firebase doesn't allow paths with special prefixes like file:// or slashes in filenames.

Fix the Filename Generation

Replace that with a unique, valid filename. A common approach is to use a UUID (guaranteed unique) plus the original file's extension:

let USER_STORAGE = Storage.storage().reference()

private func uploadVideoToDatabase(videoURL: URL, completion: @escaping (Bool)->Void){
    // Extract the original file extension (e.g., mp4, mov)
    let fileExtension = videoURL.pathExtension
    // Generate a unique, valid filename
    let filename = "\(UUID().uuidString).\(fileExtension)"
    
    USER_STORAGE.child(filename).putFile(from: videoURL, metadata: nil){(metadata, error) in
        if let error = error {
            // Print full error details for debugging
            print("Upload failed: \(error.localizedDescription)")
            print("Full error details: \(error)")
            completion(false)
            return
        }
        // Optional: Get the download URL once upload succeeds
        USER_STORAGE.child(filename).downloadURL { downloadURL, error in
            if let url = downloadURL {
                print("Video uploaded successfully! Download URL: \(url)")
            }
        }
        completion(true)
    }
}

2. Verify Your Storage Reference

Storage.storage().reference() is correct for pointing to your default Firebase Storage bucket. If you're using a non-default bucket, you'd need to specify it like this:

// For non-default buckets
let USER_STORAGE = Storage.storage().reference(forURL: "gs://your-custom-bucket-name.appspot.com")

But if you haven't changed buckets, your original reference is fine— the issue is almost certainly the filename.

3. Check Firebase Storage Security Rules

After clearing storage, double-check your security rules to ensure they allow uploads. Go to the Firebase Console > Storage > Rules. A basic rule for authenticated users looks like this:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

If you need anonymous uploads, adjust the rule to allow read, write: if true; (but be cautious with open rules in production).

4. Confirm Storage Bucket Status

  • Make sure your storage bucket isn't disabled in the Firebase Console.
  • Wait a few minutes after deleting files—sometimes the console takes time to refresh the available space.

5. Debug the Full Error

Add detailed error logging to get more context. The error object contains extra details that can pinpoint issues like permission denials or invalid paths.

Once you fix the filename generation, that should resolve the unknown error you're seeing. If you still run into issues, the detailed error log will help narrow down the next step.

内容的提问来源于stack exchange,提问作者dre_84w934

火山引擎 最新活动