【问题标题】:Getting error while uploading image using multipart request in Alamofire在 Alamofire 中使用多部分请求上传图像时出错
【发布时间】:2019-12-19 07:04:09
【问题描述】:

xcode 10.3 迅捷4.2 iPhone 应用程序

我正在使用一个帖子类型的 API 来上传图片以及表单中的一些字符串数据。我得到了成功的响应结果,但有一个错误参数表明:CredStore - performQuery - Error copying matching creds. Error=-25300

我尝试做一些研究,发现URLCredentialStorage 有问题,但我在 API 中没有任何凭据。 我查看了CredStore Perform Query error,我遇到了非常相似的问题,但在那里找不到我的解决方案。

{
    let url = route.asURL(constants: constants)
    let parameters = route.asParameters(constants: constants)
    let headers: HTTPHeaders = [
        "authorization-name": APISession.token,
        "Content-Type": "multipart/form-data"
    ]

    Log(request: URLRequest(url: url))

    Alamofire.upload(multipartFormData: { (multipartFormData) in
        for (key, value) in parameters {                
            if let strValue = value as? String, let valueData = strValue.data(using: .utf8) {
                multipartFormData.append(valueData, withName: key)
            }

            if let imgValue = value as? UIImage, let imgData = imgValue.jpegData(compressionQuality: 0.5) {
                multipartFormData.append(imgData, withName: key, mimeType: "image/jpg")
            }
        }
    }, usingThreshold: UInt64.init(), to: url, method: .post, headers: headers) { (result) in
        print(result)
        switch result{
        case .success(let upload, _, _):
            upload.uploadProgress(closure: { (progress) in
                print("Preogress is: ", progress.fractionCompleted)
            })
            upload.responseJSON { response in
                print("Succesfully uploaded")
                switch response.result {
                case .success(let value):
                    print(value)
                case .failure(let error):
                    print(error)
                }
            }
        case .failure(let error):
            print("Error in upload: \(error.localizedDescription)")
        }
    }
}

我收到这样的回复,

success(request: 2019-08-12 13:07:04.224913-0400 project name[65508:460860] CredStore - performQuery - Error copying matching creds.  Error=-25300, query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    ptcl = htps;
    "r_Attributes" = 1;
    sdmn = "url";
    srvr = "url";
    sync = syna;
}

所以我很困惑为什么我会收到带有错误参数的 success 响应。

【问题讨论】:

  • 我已经访问过stackoverflow.com/questions/46099940/…,但这并没有帮助我理解问题并找出任何解决方案。
  • 您发布的内容不是来自 Alamofire,它只是系统日志记录。您从要上传到的 API 中得到什么实际响应?
  • 你解决了吗。如果是,请简要说明

标签: alamofire multipartform-data image-uploading swift4.2 xcode10.3


【解决方案1】:

不确定,但我认为标题中的authorization-name 键不正确。应该是Authorization

【讨论】:

  • 这只是我放在这里的占位符,因为我不想透露真正的授权密钥。这是我们后端开发人员设置的自定义键。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 2019-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多