Commit dbfac601 authored by pete谢兆麟's avatar pete谢兆麟

批量上传漏洞

parent 08a31016
......@@ -41,7 +41,8 @@ class YHOSSManager: NSObject, URLSessionDelegate {
var model: YHOSSModel = YHOSSModel()
var mProvider: OSSStsTokenCredentialProvider!
var mClient: OSSClient!
var fileName: String = ""
var fileName: [String] = []
override init() {
}
......@@ -68,19 +69,24 @@ class YHOSSManager: NSObject, URLSessionDelegate {
request.uploadingData = imageData
request.bucketName = self.model.bucket
let timestamp = Date().timeIntervalSince1970
self.fileName = "\(UInt64(timestamp))" + ".jpg"
request.objectKey = self.model.bucketPath + "/" + "\(self.fileName)"
let randomInt = Int.random(in: 1...100) // 随机生成1到10之间的整数
let name = "\(UInt64(timestamp))" + "\(randomInt)" + ".jpg"
self.fileName.append(name)
request.objectKey = self.model.bucketPath + "/" + "\(name)"
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 string = "https://" + self.model.bucket + "." + "oss-cn-shenzhen.aliyuncs.com/" + self.model.bucketPath + "/" + self.fileName
let string = "https://" + self.model.bucket + "." + "oss-cn-shenzhen.aliyuncs.com/" + self.model.bucketPath + "/" + "\(self.fileName.first ?? "")"
self.fileName.removeFirst()
print("------------\(string)")
callBackBlock(string, YHErrorModel())
}
return
......@@ -94,13 +100,15 @@ class YHOSSManager: NSObject, URLSessionDelegate {
request.uploadingData = fileData
request.bucketName = self.model.bucket
let timestamp = Date().timeIntervalSince1970
self.fileName = "\(UInt64(timestamp))" + ".\(fileExtension)"
request.objectKey = self.model.bucketPath + "/" + "\(self.fileName)"
let name = "\(UInt64(timestamp))" + ".\(fileExtension)"
self.fileName.append(name)
request.objectKey = self.model.bucketPath + "/" + "\(name)"
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) {
......@@ -108,7 +116,8 @@ class YHOSSManager: NSObject, URLSessionDelegate {
let result = error.description
callBackBlock(nil, YHErrorModel())
} else {
let string = "https://" + self.model.bucket + "." + "oss-cn-shenzhen.aliyuncs.com/" + self.model.bucketPath + "/" + self.fileName
let string = "https://" + self.model.bucket + "." + "oss-cn-shenzhen.aliyuncs.com/" + self.model.bucketPath + "/" + "\(self.fileName.first ?? "")"
self.fileName.removeFirst()
callBackBlock(string, YHErrorModel())
}
return
......
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