如何解决使用JavaScript Fetch上传GraphQL文件
我正在尝试将文件上传到GraphQL服务器,我的代码如下:
var query = "{ course(id: 1) { title } }"
const proxyurl = "https://cors-anywhere.herokuapp.com/";
const url = "http://server.com:3000/graphql";
var response = await fetch(proxyurl + url,{
method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ query: query }),})
var json = await response.json();
console.log(json.data.course.title);
我不确定如何翻译有人提出的示例CURL请求:
curl -X POST \
http://localhost:3001/graphql \
-H 'Cache-Control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F 'operations={"query":"mutation ($files: [Upload!]!) {multipleUpload(files: $files) {id filename encoding mimetype path __typename}}","variables":{}}' \
-F 'map={"0":["variables.files.0"],"1":["variables.files.1"]}' \
-F '"0"=@/Users/giautm/Devel/IMG_0636.JPG' \
-F '"1"=@/Users/giautm/Devel/IMG_0637.JPG'
编辑:
这是我要完成的突变:
mutation identityValidation{
validateIdentity(identity:{
card_back:"",#must be an Upload scalar
card_front:"",#must be an Upload scalar
uniqueID:"" #string
}){
name,status,message
}
}
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。