我使用莫亞我迅速的應用程序和API之間處理通信,我能夠POST和GET數據,但無法發佈文件API服務器,下面是我的代碼無法上傳文件RXSwift莫亞多部分
enum TestApi {
...
case PostTest(obj: [String: AnyObject])
...
}
extension TestApi: TargetType {
var baseURL: NSURL {
switch self {
case .PostTest:
return NSURL(string: "http://192.168.9.121:3000")!
}
}
var path: String {
switch self {
case .PostTest:
return "/api/file"
}
}
var method: Moya.Method {
switch self {
case .PostTest:
return .POST
}
}
var parameters: [String: AnyObject]? {
switch self {
case .PostTest(let obj):
return ["image": obj["image"]!]
}
}
var sampleData: NSData {
return "".dataUsingEncoding(NSUTF8StringEncoding)!
}
var multipartBody: [MultipartFormData]? {
switch self {
case .PostTest(let multipartData):
guard let image = multipartData["image"] as? [NSData] else { return[] }
let formData: [MultipartFormData] = image.map{MultipartFormData(provider: .Data($0), name: "images", mimeType: "image/jpeg", fileName: "photo.jpg")}
return formData
default:
return []
}
}
}
和下面是我叫
return testApiProvider.request(.PostTest(obj: _file)).debug().mapJSON().map({ JSON -> EKResponse? in
return Mapper<EKResponse>().map(JSON)
})
我不收到任何迴應的方式,未擊中被送到API服務器