Commit 79c1067e authored by David黄金龙's avatar David黄金龙

Merge branch 'youhua-dev' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS into youhua-dev

* 'youhua-dev' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS:
  oss优化
  //  优化上传大文件 UI显示异常问题
  修改预览显示异常
parents 2142257f dd27986c
......@@ -538,15 +538,16 @@ extension YHCertificateUploadSheetView: UIDocumentPickerDelegate {
fileCoordinator.coordinate(readingItemAt: url, options:[.forUploading], error: &error) {
fileUrl in
uploadFilesBlock?(fileUrl)
dismiss()
uploadFilesBlock?(fileUrl)
}
url.stopAccessingSecurityScopedResource()
if let error = error {
printLog("\(error.localizedDescription)")
}
} else {
print("授权失败")
YHHUD.flash(message: "文件授权失败")
dismiss()
}
}
......
......@@ -16,21 +16,14 @@ class YHImageViewController: YHBaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
viewModel = YHWorkExperienceViewModel()
view.backgroundColor = .black
self.hidesBottomBarWhenPushed = true
if #available(iOS 11.0, *) {
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
viewModel = YHWorkExperienceViewModel()
setView()
getData()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = false
}
func setView() {
......
......@@ -71,38 +71,41 @@ class YHOSSManager: NSObject, URLSessionDelegate {
callBackBlock(nil, YHErrorModel())
return
}
request.uploadingData = imageData
request.bucketName = self.model.bucket
let timestamp = Date().timeIntervalSince1970
let randomInt = Int.random(in: 1...100) // 随机生成1到10之间的整数
let name = "\(UInt64(timestamp))" + "\(randomInt)" + ".jpg"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date())
self.fileName.append(name)
request.objectKey = "4001001" + "/" + currentDateMMdd + "/" + "\(name)"
request.contentDisposition = "inline"
request.uploadProgress = { (bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) -> Void in
printLog("bytesSent:\(bytesSent),totalBytesSent:\(totalBytesSent),totalBytesExpectedToSend:\(totalBytesExpectedToSend)")
}
let task = self.mClient.putObject(request)
task.continue({ (t) -> Any? in
let result = t
if (result.error != nil) {
callBackBlock(nil, YHErrorModel())
} else {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date())
let string = "https://" + self.model.bucket + "." + "oss-cn-shenzhen.aliyuncs.com/" + "4001001" + "/" + currentDateMMdd + "/" + "\(self.fileName.first ?? "")"
self.fileName.removeFirst()
print("------------\(string)")
callBackBlock(string, YHErrorModel())
DispatchQueue.global().async {
request.uploadingData = imageData
request.bucketName = self.model.bucket
let timestamp = Date().timeIntervalSince1970
let randomInt = Int.random(in: 1...100) // 随机生成1到10之间的整数
let name = "\(UInt64(timestamp))" + "\(randomInt)" + ".jpg"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date())
self.fileName.append(name)
request.objectKey = "4001001" + "/" + currentDateMMdd + "/" + "\(name)"
request.contentDisposition = "inline"
request.uploadProgress = { (bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) -> Void in
printLog("bytesSent:\(bytesSent),totalBytesSent:\(totalBytesSent),totalBytesExpectedToSend:\(totalBytesExpectedToSend)")
}
return
}).waitUntilFinished()
let task = self.mClient.putObject(request)
task.continue({ (t) -> Any? in
let result = t
if (result.error != nil) {
callBackBlock(nil, YHErrorModel())
} else {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date())
let string = "https://" + self.model.bucket + "." + "oss-cn-shenzhen.aliyuncs.com/" + "4001001" + "/" + currentDateMMdd + "/" + "\(self.fileName.first ?? "")"
self.fileName.removeFirst()
print("------------\(string)")
callBackBlock(string, YHErrorModel())
}
return
}).waitUntilFinished()
}
}
func putFile(file: String, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
......@@ -111,67 +114,73 @@ class YHOSSManager: NSObject, URLSessionDelegate {
callBackBlock(nil, YHErrorModel())
return
}
let fileExtension = URL(fileURLWithPath: file).pathExtension.lowercased()
request.uploadingData = fileData
request.bucketName = self.model.bucket
let timestamp = Date().timeIntervalSince1970
let name = "\(UInt64(timestamp))" + ".\(fileExtension)"
self.fileName.append(name)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date())
request.objectKey = "4001001" + "/" + currentDateMMdd + "/" + "\(name)"
request.contentDisposition = "inline"
request.uploadProgress = { (bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) -> Void in
printLog("bytesSent:\(bytesSent),totalBytesSent:\(totalBytesSent),totalBytesExpectedToSend:\(totalBytesExpectedToSend)")
}
let task = self.mClient.putObject(request)
task.continue({ (t) -> Any? in
let result = t
if (result.error != nil) {
let error: NSError = (task.error)! as NSError
let result = error.description
callBackBlock(nil, YHErrorModel())
} else {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date())
let string = "https://" + self.model.bucket + "." + "oss-cn-shenzhen.aliyuncs.com/" + "4001001" + "/" + currentDateMMdd + "/" + "\(self.fileName.first ?? "")"
self.fileName.removeFirst()
callBackBlock(string, YHErrorModel())
DispatchQueue.global().async {
let fileExtension = URL(fileURLWithPath: file).pathExtension.lowercased()
request.uploadingData = fileData
request.bucketName = self.model.bucket
let timestamp = Date().timeIntervalSince1970
let name = "\(UInt64(timestamp))" + ".\(fileExtension)"
self.fileName.append(name)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date())
request.objectKey = "4001001" + "/" + currentDateMMdd + "/" + "\(name)"
request.contentDisposition = "inline"
request.uploadProgress = { (bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) -> Void in
printLog("bytesSent:\(bytesSent),totalBytesSent:\(totalBytesSent),totalBytesExpectedToSend:\(totalBytesExpectedToSend)")
}
return
}).waitUntilFinished()
let task = self.mClient.putObject(request)
task.continue({ (t) -> Any? in
let result = t
if (result.error != nil) {
let error: NSError = (task.error)! as NSError
let result = error.description
callBackBlock(nil, YHErrorModel())
} else {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date())
let string = "https://" + self.model.bucket + "." + "oss-cn-shenzhen.aliyuncs.com/" + "4001001" + "/" + currentDateMMdd + "/" + "\(self.fileName.first ?? "")"
self.fileName.removeFirst()
callBackBlock(string, YHErrorModel())
}
return
}).waitUntilFinished()
}
}
func getPublic(url: String, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
let bucketName = self.getBucket(url)
let pathComponents = url.pathComponents
var objectKey = ""
for i in 0..<pathComponents.count {
if i == 0 || i == 1 {
} else if i == pathComponents.count - 1 {
objectKey = objectKey + pathComponents[i]
} else {
objectKey = objectKey + pathComponents[i] + "/"
DispatchQueue.global().async {
let bucketName = self.getBucket(url)
let pathComponents = url.pathComponents
var objectKey = ""
for i in 0..<pathComponents.count {
if i == 0 || i == 1 {
} else if i == pathComponents.count - 1 {
objectKey = objectKey + pathComponents[i]
} else {
objectKey = objectKey + pathComponents[i] + "/"
}
}
let task = self.mClient.presignConstrainURL(withBucketName: bucketName, withObjectKey: objectKey, withExpirationInterval: 60 * 5)
task.continue({ (t) -> Any? in
let result = t
if (result.error != nil) {
let error: NSError = (task.error)! as NSError
_ = error.description
callBackBlock(nil, YHErrorModel())
} else {
let string = result.result as! String
callBackBlock(string, YHErrorModel())
}
return
}).waitUntilFinished()
}
let task = mClient.presignConstrainURL(withBucketName: bucketName, withObjectKey: objectKey, withExpirationInterval: 60 * 5)
task.continue({ (t) -> Any? in
let result = t
if (result.error != nil) {
let error: NSError = (task.error)! as NSError
_ = error.description
callBackBlock(nil, YHErrorModel())
} else {
let string = result.result as! String
callBackBlock(string, YHErrorModel())
}
return
}).waitUntilFinished()
}
func getBucket(_ url: String) -> String {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment