Skip to main content

Upload Images

First you need to use createImages query to get the image url, and then you have to upload your image to that url.

mutation {
createImages(input: [{contentType: "image/jpg"}]) {
fields
mediaDownloadUrl
mediaId
mediaUrl
signedUrl
}
}

To upload the images you need to put all the fields in the fields in addition to content type and file to the body of the post request. Here is a JavaScript example of how to do it.

const formData = new FormData()
const parsedFields = JSON.parse(signedUrl.fields)
// The order of appended key-value into the formData matters.
Object.entries(parsedFields).forEach(([key, value]) => {
formData.append(key, String(value))
})
formData.append('Content-Type', file.type)
formData.append('file', file)

fetch(signedUrl.signedUrl, {
method: 'POST',
body: formData
})

Our javascript client have a function to automatically create and upload the images for you. It takes an extra File object as an argument.

client.media.uploadImages([{ contentType: 'image/jpg', file: file }])