我要上傳圖片到後端(PHP),我必須與參數名發送:「圖片報」斯威夫特3上傳圖片的問題(格式)
func uploadImage(token: String, userID: Int, imgStr: String,
successBlock: @escaping (JSON, Int) ->(),
failureBlock: @escaping (String) ->())
{
let params: [String: Any] = [
"picture" : imgStr
]
Alamofire.request( "\(API_URL)" + "users/\(userID)",
method: .put,
parameters: params,
encoding: JSONEncoding.default,
headers: Headers().withToken(token: token)).responseJSON
{ response in
print(response)
print(response.result)
print(response.request)
print(response.response)
response.result.error != nil
? (failureBlock(response.result.error!.localizedDescription))
: (successBlock(JSON(response.result.value),
(response.response?.statusCode)!))
}
}
但是我收到此消息
JSON: {
"picture" : [
"The picture must be a file of type: jpeg, jpg, png."
]
}
有辦法將UIImage轉換爲字符串與png/jpeg格式?
非常感謝!
在服務器端被他們期待圖像爲base64字符串格式或文件格式? – Rajat
@Rajat他們期待的文件格式(表格數據?) –
但你發送圖像作爲字符串 – Rajat