Ver Fonte

后台上传

胡志强 há 3 anos atrás
pai
commit
5bc2138db8

+ 3 - 0
Introduce/Record/INIntroduceController.swift

@@ -26,6 +26,8 @@ class INIntroduceController: BFBaseViewController {
     let exportBtn = UIButton()
     var assets: [PHAsset]?
 
+    let recordUid = getRandomStringOfLength(length: 16)
+
     let recordScreenVC = BFRecordScreenController()
     
     lazy var addMaterialBtn : UIButton  = {
@@ -286,6 +288,7 @@ class INIntroduceController: BFBaseViewController {
         controller.export.data = recordScreenVC.itemModels
         controller.export.originSoundVolumn = recordScreenVC.noSpeakVolume
         controller.export.originSoundInRecordVolumn = recordScreenVC.haveSpeakVolume
+        controller.recordUid = recordUid
         controller.coverIV.image = recordScreenVC.itemModels.first?.coverImg
         navigationController?.pushViewController(controller, animated: true)
         // 点击导出按钮上报

+ 1 - 1
Introduce/Record/INRecorderController.swift

@@ -200,7 +200,7 @@ class INRecorderController: BFBaseViewController {
         }
         addwxBtn.snp.makeConstraints { make in
             make.height.equalTo(40)
-            make.width.height.equalTo(119)
+            make.width.equalTo(119)
             make.right.equalTo(-10)
             make.top.equalTo(51)
         }

+ 61 - 1
Introduce/Record/INVideoExportController.swift

@@ -13,9 +13,16 @@ import Foundation
 import Photos
 import SwiftUI
 import UIKit
+import BFUploadKit
+import AliyunOSSiOS
 
 class INVideoExportController: BFBaseViewController {
+    let uploadData = PQUploadModel()
+    var hadUploadTask = false
     var avplayerTimeObserver: NSKeyValueObservation?
+    
+    let recordUid = getRandomStringOfLength(length: 16)
+
     let backV : UIView = {
         let v = UIView()
         v.backgroundColor = UIColor.hexColor(hexadecimal: "#1A1A1A")
@@ -264,7 +271,13 @@ class INVideoExportController: BFBaseViewController {
                     wself.playDurL.isHidden = false
                     wself.sliderView?.playStart()
                     wself.completeBtn.isHidden = false
-
+                    
+                    if !wself.hadUploadTask{
+                        wself.uploadData.localPath = fileUrl.absoluteString
+                        wself.hadUploadTask = true
+                        wself.uploadVideo()
+                    }
+                    
                     let item = AVPlayerItem(url: fileUrl)
                     wself.avplayer.replaceCurrentItem(with: item)
                     usleep(1000)
@@ -401,6 +414,8 @@ class INVideoExportController: BFBaseViewController {
         view.backgroundColor = .black
         navHeadImageView?.backgroundColor = .clear
 
+//        uploadData.videoBucketKey = recordUid
+        
         leftButton(image: nil, imageName: nil, tintColor: UIColor.white)
 
         addSubviews()
@@ -860,6 +875,51 @@ class INVideoExportController: BFBaseViewController {
 //        }
 //        UIApplication.shared.keyWindow?.addSubview(alertV)
     }
+    
+    //MARK: - Request
+    
+    func uploadVideo() {
+        
+        let uploadRequest = PQAliOssUtil.shared.allTasks[uploadData.videoBucketKey ?? ""]
+        if uploadRequest != nil, "\(uploadRequest!.callbackParam["code"] ?? "0")" == "1" {
+            return
+        }
+        // 更新进度
+        DispatchQueue.global().async {
+            PQUploadViewModel.getStsToken { [weak self] response, _ in
+                guard let wself = self else { return }
+                
+                if response == nil {
+                    BFLog(1, message: "token 获取失败")
+                    return
+                }
+                
+                BFLog(1, message: "取我方服务器STS 返回数据 \(String(describing: response))")
+                wself.multipartUpload(response: response)
+            }
+        }
+    }
+    
+    func multipartUpload(response: [String: Any]?) {
+        let FileName: String = "\(response?["FileName"] ?? "")"
+        let uploadID: String = "\(response?["Upload"] ?? "")"
+        uploadData.stsToken = response
+        uploadData.videoBucketKey = FileName
+        uploadData.uploadID = uploadID
+        if uploadData.asset != nil && isValidURL(url: uploadData.localPath) {
+            PQPHAssetVideoParaseUtil.exportPHAssetToMP4(phAsset: (uploadData.asset)!, isCancelCurrentExport: true) { [weak self] _, _, filePath, _ in
+                if filePath != nil, (filePath?.count ?? 0) > 0 {
+                    self?.uploadData.localPath = filePath
+                    PQAliOssUtil.multipartUpload(localPath: filePath!, response: response, videoSource: "videoCompose")
+                }
+            }
+        } else {
+            PQAliOssUtil.multipartUpload(localPath: uploadData.localPath ?? "", response: response, videoSource: "videoCompose")
+        }
+//        PQAliOssUtil.shared.aliOssHander = {  isMatarialUpload, materialType, _, code, objectkey, _, _, _, _, _, _, _, _, _ in
+//
+//        }
+    }
 }
 
 extension INVideoExportController {