Image without content

Hi guys,
Im using the Content Management API, on HTTP directly. My strings field’s, like name, description… are working, but my image update isnt.


When the Documentation says: " Now you can use the obtained URL to perform a PUT request directly to AWS, uploading the raw content of the file as the request body (no multipart upload!)", to get the upload_id, step 2, how can i do it using Javascript ? All the other steps are working, but the error is on this step 2.

Hello @problemchild007m

With javascript you can use the Node client to simplify the file upload process, you can see its syntax by selecting “Javascript” on the top of the documentation page:

image

For pure HTTP, what probably happened, is that the raw binary of the image wasn’t included in the step 2, making the creation of the upload, with the name and other specified fields, but not the actual content of the image.

Thanks for the attention. There is how im doing this step 2. :
This step return the status code 201 (Created), but the width and height of the image is null.

async function createUpload() {
const imageUploaded = await getAWSUploadUrl(); //URL from step 1
const productImage = document.querySelector(’[data-input-image]’).files[0]; //Input type file
let reader = new FileReader();

await fetch(`${imageUploaded.data.attributes.url}`, {   //Fetch the URL returned on step 1.
  method: 'PUT', 
  body: reader.onload = () => {
    return reader.result;
  }
});
reader.readAsBinaryString(productImage);

}

@problemchild007m

Could you send us over at support@datocms.com the entire file you are using for this process? This way we can take a closer look at the issue and point out exactly what could be going wrong in the code.

Just as an addition note, for the purpose of feedback, would you mind sharing why you’re not using the Dato Node client for this? As it can simplify the upload process quite a lot from raw HTTP requests

Thank you!

Ok, i will send my file .js on the email.

I cant use the Dato Node client because i’m updating this project on a static server, so i cannot use import export, to use the lib.