8.9 C
New York
Monday, March 10, 2025

ios – Getting the “Did not concern sandbox extension” error when importing movies to Firebase


I get the “Did not concern sandbox extension” error when importing videoss to Firebase. My pictures add simply effective, solely movies trigger downside.

func testUploadLocalVideo() {
        if let localVideoURL = Bundle.most important.url(forResource: "IMG_3787", withExtension: "MOV") {
            print("Making an attempt to add native video: (localVideoURL)")
            uploadVideoToFirebase(fileURL: localVideoURL)
        } else {
            print("❌ Native check video not discovered.")
        }
    }
    
func uploadImageToFirebase(picture: UIImage) {
    let storageRef = Storage.storage().reference()
    guard let imageData = picture.jpegData(compressionQuality: 0.75) else {
        print("Error changing picture to information")
        return
    }
    
    let fileName = UUID().uuidString + ".jpg"
    let imageRef = storageRef.little one("pictures/(fileName)")
    
    imageRef.putData(imageData, metadata: nil) { metadata, error in
        if let error = error {
            print("Error importing picture: (error.localizedDescription)")
            return
        }
        imageRef.downloadURL { url, error in
            if let error = error {
                print("Error getting obtain URL: (error.localizedDescription)")
                return
            }
            if let downloadURL = url {
                DispatchQueue.most important.async {
                    self.selectedImages.append(picture)
                    self.isMediaSelected = true
                }
                print("✅ Picture uploaded efficiently: (downloadURL)")
            }
        }
    }
}

func uploadVideoToFirebase(fileURL: URL) {
    print("Beginning video add with fileURL: (fileURL)")
    
    // Create a brief file URL inside your app's sandbox
    let tempFileURL = FileManager.default.temporaryDirectory.appendingPathComponent(fileURL.lastPathComponent)
    
    do {
        // Copy the video file to the momentary location
        strive FileManager.default.copyItem(at: fileURL, to: tempFileURL)
        print("✅ Video copied to momentary location: (tempFileURL)")
        
        // Add the video from the momentary location
        uploadVideoFromTempFile(tempFileURL: tempFileURL)
    } catch {
        print("❌ Error copying video file: (error)")
    }
}

func uploadVideoFromTempFile(tempFileURL: URL) {
    // 1. Generate a novel filename utilizing UUID
    let fileName = UUID().uuidString + ".mov"
    
    // 2. Create a reference to the video file in Firebase Storage
    let storageRef = Storage.storage().reference().little one("movies/(fileName)")
    
    // 3. Create a metadata object to retailer the video's content material kind
    let metadata = StorageMetadata()
    metadata.contentType = "video/quicktime"
    
    // 4. Load video information
    guard let videoData = strive? Information(contentsOf: tempFileURL) else {
        print("❌ Unable to create video information from momentary file")
        return
    }
    
    // 5. Add the video information instantly utilizing putData
    storageRef.putData(videoData, metadata: metadata) { metadata, error in
        if let error = error {
            print("❌ Error importing video: (error.localizedDescription)")
        } else {
            // Get obtain URL from the storage reference
            storageRef.downloadURL { url, error in
                if let downloadURL = url?.absoluteString {
                    DispatchQueue.most important.async {
                        self.selectedVideos.append(tempFileURL) // Retailer tempFileURL
                        self.isMediaSelected = true
                    }
                    print("✅ Video uploaded efficiently: (downloadURL)")
                } else {
                    print("Video uploaded efficiently, however obtain URL isn't out there.")
                }
            }
        }
    }
}

Regardless of attempting numerous options equivalent to dealing with security-scoped URLs and copying the video to a brief location, the error persists. This means that there could be different elements at play, equivalent to lacking entitlements, concurrency points, reminiscence stress, issues with the Firebase SDK, device-specific restrictions, or interfering code. which perhaps I did not do any of those steps proper(because it did not work). My aim is for the movies to add to firebase identical to the pictures

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles