Vuejs 3 and Cloudflare Images

Hi, I have spent couple of days trying to upload an image from my vuejs (localhost:3000) dev environment to cloud image, and im getting CORS error

read articles, still could get the code to work.

– my code below–
if (data.logo instanceof File) {
try {
const formData = new FormData();
formData.append(‘file’, data.logo);
formData.append(‘requireSignedURLs’, false.toString());
formData.append(‘metadata’, ‘{“key”:“value”}’);

    const res = await fetch(url, {
      method: 'POST',
      body: formData,
      headers: {
        'Authorization': 'Bearer YbC_ugKM00caSlNkbRA1SB-WbgaeVSzLs82c64RB',
      },
      referrerPolicy: 'no-referrer',
    });

    if (res.ok) {
      const responseJson = await res.json();
      console.log('Upload successful:', responseJson);
    } else {
      console.log('Failed to upload. Status:', res.status);
    }
  } catch (error) {
    console.error('Error uploading logo:', error);
  }
} else {
  console.log('data.logo is null or not a File object.');
}

This topic was automatically closed after 15 days. New replies are no longer allowed.