我正在尝试使用Alamofire将图像上传到服务器,但我的代码不起作用.这是我的代码:
var parameters = ["image": "1.jpg"]
let image = UIImage(named: "1.jpg")
let imageData = UIImagePNGRepresentation(image)
let urlRequest = urlRequestWithComponents("http://tranthanhphongcntt.esy.es/task_manager/IOSFileUpload/", parameters: parameters, imageData: imageData)
Alamofire.upload(urlRequest.0, data: urlRequest.1)
.progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
println("\(totalBytesWritten) / \(totalBytesExpectedToWrite)")
}
.responseJSON { (request, response, JSON, error) in
println("REQUEST \(request)")
println("RESPONSE \(response)")
println("JSON \(JSON)")
println("ERROR \(error)")
}
Run Code Online (Sandbox Code Playgroud)
这是urlRequestWithComponents方法:
func urlRequestWithComponents(urlString:String, parameters:Dictionary<String, String>, imageData:NSData) -> (URLRequestConvertible, NSData) {
// create url request to send
var mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: urlString)!)
mutableURLRequest.HTTPMethod = Alamofire.Method.POST.rawValue
let boundaryConstant = …Run Code Online (Sandbox Code Playgroud) 我有一些这样的代码:
let first = Observable<Int>.create({ observer -> Disposable in
observer.onNext(1)
return Disposables.create()
})
let second = Observable.of(4, 5, 6)
let observableConcat = Observable.concat([first, second])
observableConcat.subscribe({ (event) in
print(event)
})
Run Code Online (Sandbox Code Playgroud)
我对 concat 运算符的了解是“它订阅集合的第一个序列,中继其元素直到它完成,然后移动到下一个。重复该过程,直到使用了集合中的所有可观察对象”。所以我期望代码片段的结果是 1、4、5、6,但我得到的只是 1。请教我我对 concat 运算符的误解。
非常感谢。