0
我使用這個代碼(SWIFT)上傳圖片該用戶從他們的照片選擇到服務器:
let imageFormatted = UIImageJPEGRepresentation(imageView.image!, 0.5);
let uuid = NSUUID().UUIDString
print ("MARK -- UUID is " + uuid)
Alamofire.upload(
.POST,
"http://www.memer.onlie/upload.php",
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(data: imageFormatted!, name: "imagefile",
fileName: uuid + ".jpg", mimeType: "image/jpeg")
},
encodingCompletion: { encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.validate()
upload.responseJSON { response in
dispatch_async(dispatch_get_main_queue()) {
self.displayAlert("Uploaded!", message: "Your meme was uploaded, and you might see it in the app soon!", responseButtonText: "<3")
}
var json = JSON(data: response.data!)
print ("MARK -- JSON response: " + json["response"].stringValue)
}
print ("MARK -- Upload success!")
case .Failure(let encodingError):
print(encodingError)
print ("MARK -- Upload failure!")
self.displayAlert("Issue uploading.", message: "There was an issue uploading your meme.", responseButtonText: "Aww :(")
}
}
)
沒有圖片被上傳到服務器。我能糾正什麼才能使這個工作?
已編輯的代碼。
我正在使用這個,查看編輯後的代碼,但它沒有發送到服務器,也沒有響應。 @woogii –
難道你沒有任何HTTP頭或額外的參數?你從答覆中得到的錯誤是什麼?你可以參考這個[線程](http://stackoverflow.com/questions/26121827/uploading-file-with-parameters-using-alamofire/26747857#26747857)它顯示了關於Alamorfire上傳請求的各種示例代碼。 – woogii