When my picture is uploaded to firebase theres a additional area a videourl is added and that enables a video to be uploaded when the person picture submit is fetch from firebase however when the video is uploaded, it’s uploaded by itself with no imageurl fields
I’m caught on this code i’m not understanding why the videourl is being uploaded accurately to firebase however not the picture. I would like my person to have the ability to choose a picture or video from their picture album utilizing photospickeritem to add their submit individually How am i able to repair this code to make that occur ?
class UploadPostViewModel: NSObject, ObservableObject {
@Printed var didUploadPost = false
@Printed var movies = [Video]()
@Printed var profileImage: Picture?
@Printed var selectedImage: PhotosPickerItem? {
didSet { Job { await dataImage()
Job { strive await sendVideo() }
}
}
}
personal var uiImage: UIImage?
func uploadPost(caption: String) async throws {
guard let uid = Auth.auth().currentUser?.uid else { return }
var videoUrl: String? = nil
if let objects = selectedImage {
let videoData = strive await objects.loadTransferable(sort: Knowledge.self)
videoUrl = (strive await VideoUploader.uploadVideo(withData: videoData!))
}
var imageUrl: String? = nil
if let picture = uiImage {
imageUrl = strive await ImageUploader.uploadImage(picture: picture , sort: .submit)
}
let submit = Submit(
ownerUid: uid,
textual content: textual content,
videoUrl: videoUrl, likes: 0,
replyCount: 23,
imageUrl: imageUrl, timestamp: Timestamp()
)
strive await PostService.uploadPost(submit)
self.didUploadPost = true
}
func dataImage() async {
guard let merchandise = selectedImage else { return }
guard let knowledge = strive? await merchandise.loadTransferable(sort: Knowledge.self) else { return }
guard let uiImage = UIImage(knowledge: knowledge) else { return }
self.uiImage = uiImage
self.profileImage = Picture(uiImage: uiImage)
}
func sendVideo() async throws {
guard let merchandise = selectedImage else {return}
guard let videoData = strive await merchandise.loadTransferable(sort: Knowledge.self) else {return}
guard let videoUrl = strive await VideoUploader.uploadVideo(withData: videoData) else { return}
strive await Firestore.firestore().assortment("movies").doc().setData(["videoUrl": videoUrl])
}
func fetchVideos() async throws {
let snapshot = strive await Firestore.firestore().assortment("movies").getDocuments()
self.movies = snapshot.paperwork.compactMap({ strive? $0.knowledge(as: Video.self) })
}
}