美文网首页
The request of a upload task sho

The request of a upload task sho

作者: 哈尔湖 | 来源:发表于2024-01-22 16:01 被阅读0次

升级Xcode 15 后,上传图片到 aws s3 xcode 控制台打印如下警告

  • The request of a upload task should not contain a body or a body stream, use upload(for:fromFile:), upload(for:from:), or supply the body stream through the urlSession(_:needNewBodyStreamForTask:) delegate method

  • 大概意思:上传任务的请求不应包含正文或正文流

问题代码如下,虽然警告但不影响使用。

        var request = URLRequest(url: url)
        request.httpMethod = "PUT"
        request.httpBody = imageData;
        request.setValue("image/jpeg", forHTTPHeaderField: "Content-Type")
        request.timeoutInterval = 60
        AF.upload(InputStream(), with: request).uploadProgress { progress  in
            
            progressBlock(progress)
        }.validate().response { AFDataResponse in
           
       }

更改后,问题解决

        var headers = AF.sessionConfiguration.headers;
        headers.add(name: "Content-Type", value: "image/jpeg");

        AF.upload(imageData,
                  to: url,
                  method: .put,
                  headers: headers,
                  requestModifier: {$0.timeoutInterval = 60}
        
        ).uploadProgress { progress in
            
            print(progress);
            progressBlock(progress);
        }.validate().response { AFDataResponse in
            
        }

相关文章

网友评论

      本文标题:The request of a upload task sho

      本文链接:https://www.haomeiwen.com/subject/mjwyodtx.html