System Information
- Strapi Version: 3.3.4
- Operating System: MacOS 11.0
- Database: sqlite
- Node Version: 14.15.1
- NPM Version: 6.14.8
- Yarn Version: 1.22.10
Hello everyone,
While I am quite sure I am missing something crucial here I can’t really figure out what. I’m trying to implement a single file upload. I didn’t set any service to upload to since I want to save it to my file system (perhaps that is the case), or I need to format data I am sending in a different way so the graphql can resolve it.
Either way here is the code:
import React, { useState } from 'react'
import { gql, useMutation } from '@apollo/client'
const UPLOAD_PART_IMAGE = gql`
mutation($file: Upload!) {
upload(file: $file) {
id
name
}
}
`
function AddPartImage() {
const [image, setImage] = useState()
const handleSubmit = (event) => {
event.preventDefault()
addImage()
}
const [addImage] = useMutation(UPLOAD_PART_IMAGE, {
variables: {
file: image,
}
})
return (
<div>
<form onSubmit={(event) => {handleSubmit(event)}}>
<input type="file" name="files" alt="image" onChange={(e) => {setImage(e.target.files[0])}} />
<button type="submit">Upload</button>
</form>
</div>
)
}
...
I get following GraphQL error:
If it is not obvious from the example I am trying to upload the file to Strapi via separate React frontend app
Thanks