Apollo Kotlin 文件上传失败,服务器返回500错误求助
Apollo Kotlin 文件上传报错问题
问题描述
按照Apollo官方文档的说明使用上传mutation上传图片时,始终收到服务器返回的500错误:
{"statusCode":500,"code":"ERR_INVALID_ARG_TYPE","error":"Internal Server Error","message":"The \"string\" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Object"}
使用的Apollo版本为3.7.1
代码与日志
发起请求的Kotlin代码
val file = File(filePath) val upload = DefaultUpload.Builder().fileName(file.name).content(file).build() val response = apolloClient.mutation(UploadAvatarMutation(file = upload)).execute()
注意事项
上述代码中,无法解析文档中提到的File.toUpload()方法
请求信息
--> POST https://api.goling.com/v1 Content-Type: multipart/form-data; boundary=0cabe113-64eb-4785-a60a-7a0b1fd1e23f Content-Length: 701 X-APOLLO-OPERATION-ID: e3250dbd528eb9c0628768ad0a565706bfc9c5f5d5ad9036df2a73dbc20ea6f4 X-APOLLO-OPERATION-NAME: UploadAvatar 20Accept: multipart/mixed; deferSpec=20220824, application/json --> END POST (one-shot body omitted)
响应信息
<-- 500 https://api.goling.com/v1 (256ms) date: Sat, 19 Nov 2022 13:18:02 GMT content-type: application/json; charset=utf-8 cf-ray: 76c93ac00ecc5fbe-MRS strict-transport-security: max-age=15552000; includeSubDomains vary: Accept-Encoding cf-cache-status: DYNAMIC access-control-allow-credentials: true content-security-policy: default-src 'self';base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests cross-origin-embedder-policy: require-corp cross-origin-opener-policy: same-origin cross-origin-resource-policy: same-origin origin-agent-cluster: ?1 referrer-policy: no-referrer x-content-type-options: nosniff x-dns-prefetch-control: off x-download-options: noopen x-frame-options: SAMEORIGIN x-permitted-cross-domain-policies: none x-xss-protection: 0 server: cloudflare alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400 {"statusCode":500,"code":"ERR_INVALID_ARG_TYPE","error":"Internal Server Error","message":"The \"string\" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Object"} <-- END HTTP (211-byte body)
内容的提问来源于stack exchange,提问作者David Ibrahim
相关产品推荐
相关产品推荐

