Search code examples
axiossanity

How to use Sanity's assets HTTPS API and send a filename through the query?


I am using axios for the request module. I just want to be able to specify the filename of the image and can't figure out how to do this with this endpoint:

const { data } = await axios({
   method: `post`,
   url: `https://${projectId}.api.sanity.io/v1/assets/images/${dataset}`,
   data: body, // readable stream for image here
   headers: {
      "Content-Type": contentType || `application/json`,
      Authorization: `Bearer ${process.env.SANITY_TOKEN}`
    },
}) 

I don't really want to use the @sanity/client.


Solution

  • Just need to add a Query String to the end of the url:

    https://${projectId}.api.sanity.io/v1/assets/images/${dataset}?filename=myImage.jpg