我尝试使用预先签名的请求将文件上传到S3。
Alamofire.upload(multipartFormData: { multipartFormData in
//Attempt 1
multipartFormData.append(InputStream(data: data), withLength: UInt64(data.count), headers: [
"Content-Type": " "
])
//Attempt 2
//multipartFormData.append(data, withName: "file", fileName: fileName, mimeType: "application/json")
}, with: router) { encodingResult in
switch encodingResult {
case .success(let upload,_,_):
upload.validate()
upload.uploadProgress(closure: { progress in
guard let progressCallback = progressCallback else { return }
progressCallback(progress.fractionCompleted)
})
upload.responseString(completionHandler: { response in
switch response.result {
case .success(let json):
self.handleSuccessResponse(withJson: json, toCallback: callback)
case .failure(let error):
self.handleFailResponse(withData: response.data, toCallback: callback)
}
})
case .failure:
break
}
}
我正在获取状态代码403
并回复:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>************</AWSAccessKeyId>
<StringToSign>POST\n\nmultipart/form-data;
boundary=alamofire.boundary.e001fb3981bbd6fc\n1522072451\nx-amz-
server-side-encryption:AES256\n/api/****/test.json</StringToSign>
如果我理解正确的问题是boundary=alamofire.boundary.e001fb3981bbd6fc
如何删除此内容?
由于