我使用apollo server
和apollo upload client
。
这是我发送文件的客户端代码:
const updateMarketing = gql`
mutation UpdateMarketing(
$file1: Upload
$file2: Upload
$file3: Upload
$payload: MarketingInput!
) {
updateMarketing(
file1: $file1
file2: $file2
file3: $file3
payload: $payload
) {
isSuccess
error
data
}
}
`;
以及此突变代码:
<Mutation mutation={updateMarketing}>
{(
updateMarketing,
{ data, loading, error }
) => (
<div>
<form
onSubmit={e => {
e.preventDefault();
console.log(e.target.file1.files[0]);
updateWmsSkuTicketMarketing({
variables: {
file1: e.target.file1.files[0],
file2: e.target.file2.files[0],
file3: e.target.file3.files[0],
payload: {
id: e.target.id.value,
jobId: e.target.jobId.value
}
}
});
}}
>
<input
type="text"
id="id"
name="id"
placeholder="id"
/>
<br />
<input
type="text"
id="jobId"
name="jobId"
placeholder="job id"
/>
<br />
<input
type="file"
id="file1"
name="file1"
/>
<br />
<input
type="file"
id="file2"
name="file2"
/>
<br />
<input
type="file"
id="file3"
name="file3"
/>
<br />
<button type="submit">
update marketing
</button>
</form>
{loading && (
<div>Updating for marketing</div>
)}
{data && (
<div>
Update markting Proccess
is finished
</div>
)}
{error && (
<div>
Error update marketing…
</div>
)}
</div>
)}
</Mutation>
在服务器上,我试图获取文件:
const updateMarketing = ({ payload, token, file1, file2, file3 }) =>
new Promise((resolve, reject) => {
try {
console.log(file1, payload);
file1
.then(({ stream, filename }) => {
//get stream
});
}
// catch
但发生错误:file1.then is not a function
和console.log(file1)
在服务器上:{}
可能是我在客户端中写错了,但是我找不到。
请帮助我,我哪里写错了以及如何解决?