gpt4 book ai didi

ios - 使用多部分请求上传文件 - Swift 4

转载 作者:可可西里 更新时间:2023-11-01 00:55:22 25 4
gpt4 key购买 nike

我必须使用多部分请求在服务器上上传文件。对于网络通话,我使用的是 Alamofire。

What i have done so far is below

请求服务:
enter image description here

多部分请求:-

let headers: HTTPHeaders = [
"Content-type": "multipart/form-data"
]
let fileData = Filedata() // getting data from local path

let URL = try! URLRequest(url: "https://SomeUrl/upload", method: .post, headers: headers)
Alamofire.upload(multipartFormData: { (multipartFormData) in

//multipartFormData.append(fileData, withName: "image", fileName: "image", mimeType: "image/png")
multipartFormData.append(fileData, withName: "file")

}, with: URL, encodingCompletion: { (result) in

switch result {
case .success(let upload, _, _):

upload.responseJSON { response in
print(response)
}
case .failure(let encodingError):
print(encodingError)
}

})

回应:-

{ Status Code: 400, Headers {
Connection = (
close
);
"Content-Type" = (
"application/json;charset=UTF-8"
);
Date = (
"Tue, 15 May 2018 10:34:15 GMT"
);
"Transfer-Encoding" = (
Identity
);
} }
[Data]: 171 bytes
[Result]: SUCCESS: {
error = "Bad Request";
message = "Required request part 'file' is not present";
path = "/files/safebolt.org/upload";
status = 400;
timestamp = "2018-05-15T10:34:15.715+0000";
}

Can anyone please tell me what i am doing wrong with request ?

最佳答案

尝试:

multipartFormData.append(fileData, withName: "file", fileName: "file", mimeType: "image/png")

关于ios - 使用多部分请求上传文件 - Swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50348265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com