Post

Replies

Boosts

Views

Activity

AVAssetExportSession fails due to "The operation could not be completed" when uploading to https url
I am trying to upload a video file after compressing it to our AWS server. When uploading without compressing, it works fine. func uploadVideoToUrlWithoutEncoding(videoUrl: URL, uploadUrl: URL) async -> Bool {   var videoData = Data()   do {     videoData = try Data(contentsOf: videoUrl)   } catch {     print("Failed to get video data")     return false   }       var request = URLRequest(url: uploadUrl)   request.setValue("blobs/mov", forHTTPHeaderField: "Content-Type")   request.httpMethod = "PUT"       do {     let (data, response) = try await URLSession.shared.upload(for: request, from: videoData)     return true   } catch {     print("URL upload failed")     return false   } } Now I am trying to do the same but with compression using AVAssetExportSession. It always fails :( The code I used is the following: func uploadVideoToUrl(videoUrl: URL, uploadUrl: URL) async {   let anAsset = AVAsset(url: videoUrl)   let preset = AVAssetExportPresetLowQuality   let outFileType = AVFileType.mov       AVAssetExportSession.determineCompatibility(ofExportPreset: preset, with: anAsset, outputFileType: outFileType) { isCompatible in     guard isCompatible else {       return     }           guard let exportSession = AVAssetExportSession(asset: anAsset, presetName: preset) else {       return     }           exportSession.outputFileType = outFileType     // Testing path/output url     let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL     let filePath = documentsDirectory.appendingPathComponent("rendered-Video.mov") // try this for testing     exportSession.outputURL = uploadUrl // if I set to filePath this works     exportSession.exportAsynchronously {       switch exportSession.status {       case .failed:         let errorString: String = exportSession.error?.localizedDescription ?? "Unknown Error"         print("Failed to upload video due to..." + errorString)         print(exportSession.error!)       case .cancelled:         print("Upload video cancelled...")       case .completed:         print("Upload video complete!")       default:         print("Upload video unload error encountered")         break       }     }   } } This always errors out giving the error: Failed to upload video due to...The operation could not be completed Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12105), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x6000019dd5f0 {Error Domain=NSOSStatusErrorDomain Code=-12105 "(null)"}} Does anyone know why this is happening? I also tried changing the outputUrl to be local file path just to check. Setting to local path works. So it must be something about the http url I set. The actual url I use is something like: https://ouraddress.amazonaws.com/location/fileName.mov?X-Amz-Security-Token=tokenvalue My current guess is that it has to do something with the security of the url? Any help is greatly appreciated!
2
0
1.1k
Dec ’22
Bottom Sheet not disappearing when I move to previous view
Hello everyone, I am trying to use BottomSheet (UISheetPresentationController) in my project and there is an issue where I can't automatically dismiss bottom sheet when I move back to parent view. For reproduction steps, I have essentially: Home view with button to go to next view Next view has bottom sheet that automatically opens When I go back to parent view, the bottom sheet is still open To use BottomSheet in SwiftUI, I used bottomSheet by adamfootdev (I also used a similar method based on createwithswift, but both had same issues so I don't think there is an issue with implementation). Also to solve the issue, I first tried using onDisappear and found out it was not called early enough, so I used onWillDisappear from stack overflow. Below is the main reproduction steps: import SwiftUI import BottomSheet // Based on https://github.com/adamfootdev/BottomSheet struct BottomSheetParent: View {   @State var isPresented: Bool = false   var body: some View {     VStack {       Button(action: {isPresented.toggle()}) {         Text("Press For Bottom Sheet")       }     }     .bottomSheet(isPresented: $isPresented, largestUndimmedDetentIdentifier: .large) {       Text("Hello from Bottom Sheet")     }     // onDisappear was not early enough, so I tried onWillDisappear     // Based on https://stackoverflow.com/questions/59745663/is-there-a-swiftui-equivalent-for-viewwilldisappear-or-detect-when-a-view-is     //.onWillDisappear() {     //  isPresented = false     //}   } } struct BottomSheetReproHome: View {   var body: some View {     NavigationLink(destination: BottomSheetParent()) {       Text("Button To Next Screen")     }   } } struct BottomSheetReproHome_Previews: PreviewProvider {   static var previews: some View {     NavigationView {       BottomSheetReproHome()     }   } } To use bottom sheet, add following dependency dependencies: [ .package(url: "https://github.com/adamfootdev/BottomSheet.git", from: "0.1.3") ] You can uncomment out onWillDisappear to see exactly what I tried. If you have a better solution, you don't have to use this. To use it add the following for onWillDisappear: import UIKit import SwiftUI struct WillDisappearHandler: UIViewControllerRepresentable {   func makeCoordinator() -> WillDisappearHandler.Coordinator {     Coordinator(onWillDisappear: onWillDisappear)   }   let onWillDisappear: () -> Void   func makeUIViewController(context: UIViewControllerRepresentableContext<WillDisappearHandler>) -> UIViewController {     context.coordinator   }   func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<WillDisappearHandler>) {   }   typealias UIViewControllerType = UIViewController   class Coordinator: UIViewController {     let onWillDisappear: () -> Void     init(onWillDisappear: @escaping () -> Void) {       self.onWillDisappear = onWillDisappear       super.init(nibName: nil, bundle: nil)     }     required init?(coder: NSCoder) {       fatalError("init(coder:) has not been implemented")     }     override func viewWillDisappear(_ animated: Bool) {       super.viewWillDisappear(animated)       onWillDisappear()     }   } } struct WillDisappearModifier: ViewModifier {   let callback: () -> Void   func body(content: Content) -> some View {     content       .background(WillDisappearHandler(onWillDisappear: callback))   } } extension View {   func onWillDisappear(_ perform: @escaping () -> Void) -> some View {     self.modifier(WillDisappearModifier(callback: perform))   } } You can see that bottom sheet does not disappear when I move back to parent view. How do I solve this issue? I tried onWillDisappear, but this was almost a solution because when I swipe back, that dismissed the bottom sheet and not go back to parent view. The back button did what it is supposed to though.
0
0
1.2k
Jun ’22