請檢查一下。
var imgData = Data()
if image != nil {
imgData = UIImageJPEGRepresentation(image!, 1.0)!
}
Alamofire.upload(multipartFormData:{ multipartFormData in
multipartFormData.append(imgData, withName: "image", fileName: "imagefilename", mimeType: "image/jpeg")
for (key, value) in param {
//let data = (value as! String).data(using: String.Encoding.utf8)!
let data = (value as AnyObject).data(using: String.Encoding.utf8.rawValue)
multipartFormData.append(data!, withName: key as! String)
}
},
usingThreshold:UInt64.init(),
to:fullLink,
method:.post,
headers:[:],
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.uploadProgress { progress in // main queue by default
print("Upload Progress: \(progress.fractionCompleted)")
}
upload.responseJSON { response in
debugPrint(response)
if let TempresponseDict:NSDictionary = response.result.value as? NSDictionary {
if (TempresponseDict.object(forKey: "response") as? String)?.caseInsensitiveCompare("success") == .orderedSame {
CompletionHandler(true, TempresponseDict)
}
else {
var statusCode = response.response?.statusCode
if let error = response.result.error as? AFError {
statusCode = error._code // statusCode private
switch error {
case .invalidURL(let url):
print("Invalid URL: \(url) - \(error.localizedDescription)")
case .parameterEncodingFailed(let reason):
print("Parameter encoding failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
case .multipartEncodingFailed(let reason):
print("Multipart encoding failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
case .responseValidationFailed(let reason):
print("Response validation failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
switch reason {
case .dataFileNil, .dataFileReadFailed:
print("Downloaded file could not be read")
case .missingContentType(let acceptableContentTypes):
print("Content Type Missing: \(acceptableContentTypes)")
case .unacceptableContentType(let acceptableContentTypes, let responseContentType):
print("Response content type: \(responseContentType) was unacceptable: \(acceptableContentTypes)")
case .unacceptableStatusCode(let code):
print("Response status code was unacceptable: \(code)")
statusCode = code
}
case .responseSerializationFailed(let reason):
print("Response serialization failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
// statusCode = 3840 ???? maybe..
}
print("Underlying error: \(error.underlyingError)")
}
else if let error = response.result.error as? URLError {
print("URLError occurred: \(error)")
}
else {
print("Unknown error: \(response.result.error)")
}
print("\(statusCode)") // the status code
CompletionHandler(false, TempresponseDict)
}
}
else {
CompletionHandler(false, NSDictionary())
}
}
case .failure(let encodingError):
print(encodingError)
CompletionHandler(false, NSDictionary())
}
})
}
其中是該行中視頻的URL? let fileURL = Bundle.main.url(forResource:「video」,withExtension:「mov」) –
它意味着獲取名爲video.mov的文件在您的主包中的URL。 – bubuxu
這是示例代碼,而不是特定於您問題的代碼。該行爲應用程序包創建名爲「video.mov」的文件的文件url。 –