I am trying to upload a image and a video to firebase but they are uploading together I want to upload them separately so when I fetch my user post from firebase they don’t display together like this the videoUrl is added to imageurl but I want to upload them separately .
How do I set up my code to upload my image and videoUrl to firebase without receiving any errors
I have tried using different methods but I ran into some errors
Cannot convert value of type ‘PhotosPickerItem’ to expected argument type ‘String’
var videoUrl: String? = nil
if let vidUrl = selectedImage{
guard let url = URL(string: vidUrl) else { return }
let videosUrl = try await VideoUploader.uploadVideoToStorage(withUrl: url)
}
And I also tried this method also and it gave me a error as well
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
var videoUrl: String? = nil
if let url = URL(string: videoUrl!) {
let videoUrl = try await VideoUploader.uploadVideoToStorage(withUrl: url)
}
class UploadViewModel: NSObject, ObservableObject {
@Published var error: Error?
@Published var videos = [Video]()
@Published var selectedVideoUrl: URL?
@Published var selectedImage: PhotosPickerItem? {
didSet {
Task { try await uploadVideo() }
}
}
private var uiImage: UIImage?
private var videoData: Data?
func uploadPost() async throws {
guard let uid = Auth.auth().currentUser?.uid else { return }
var videoUrl: String? = nil
if let url = URL(string: videoUrl!) {
let videoUrl = try await VideoUploader.uploadVideoToStorage(withUrl: url)
}




