Home > front end >  Error uploading video to cloud storage swiftui
Error uploading video to cloud storage swiftui

Time:01-25

I have a video creating process where a user selects a video using UIImagePickerController. After selecting a video, the url of the video is passed to the video details page. Once the user completes the details and clicks upload, I run this code:

if canProceed(){
    
    let fileName = "\(UUID().uuidString).mov"
    
    storage.reference(withPath: "videos/\(Auth.auth().currentUser?.email ?? "")/\(fileName)").putFile(from: vidURL, metadata: nil) { metadata, err in
        
        if err != nil{
            print(err)
            return
        }
        
        metadata?.storageReference?.downloadURL(completion: { url, err in               
            if err != nil{
                print(err)
                return
            }
            
            db.collection("reelPool").document(fileName).setData(["url": url])
        })            
    }        
}

Nothing is uploaded to cloud storage and the return is:

Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response."

CodePudding user response:

Did you remember to edit your Firestore rules to allow for read/write access? Your database may not allow writing or only allow writing for authenticated users. Typically Code -13000 is related to permissioning issues on the database.

CodePudding user response:

HI I think Here is your answer Just try with it , // Url is Video Url Which you will get when Pick a video from Image Picker

func upload(file: URL, completion: @escaping ((_ url : URL?) -> ())) {

    let name = "\(yourFile Name)).mp4"
    do {
        let data = try Data(contentsOf: file)
        
        let storageRef =
    Storage.storage().reference().child("Videos").child(name)
        if let uploadData = data as Data? {
            let metaData = StorageMetadata()
    metaData.contentType = "video/mp4"
    storageRef.putData(uploadData, metadata: metaData
                , completion: { (metadata, error) in
        if let error = error {
            completion(nil)
        }
        else{
        storageRef.downloadURL { (url, error) in
               guard let downloadURL = url else {
           completion(nil)
           return
           }
           completion(downloadURL)
               }
            print("success")
                                }
                               })
        }
    }catch let error {
        print(error.localizedDescription)
    }

And then You will get Url of the Video, now run code of firestore and Pass Url in dictionary .

  •  Tags:  
  • Related