Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
React js: No 'Access-Control-Allow-Origin' header is present on the requested resource while using htmlToImage

I am trying to use htmlToImage method but is showing the error "Access to fetch at " / aws image url / " from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

The image url which I am using in img tag is coming from aws s3 bucket. And on AWS s3 we have already configured CORS

AllowedOrigins as "". AllowedHeaders as "".

This is my code.

import React, { Component } from 'react'
import * as htmlToImage from "html-to-image";

export default class DownloadableImage extends Component {
constructor(props) {
    super(props)

    this.state = {
   
    }
  }
 handleDownloadImage = ()=>{
  const post = document.getElementById("generateImage");
    htmlToImage
      .toJpeg(post, {
        style: {
          backgroundColor: "#fff",
        },
        quality: 0.95,
      })
      .then(function (dataUrl) {
        var link = document.createElement("a");
        link.download = "download.jpeg";
        link.href = dataUrl;
        link.click();
      })
      .catch((error) => console.log(error, "error"));
}
  render() {
    return (  
        <div id="generateImage">
            <img class="img-style" src="imgUrl" alt="download_image"> 
        <div>
        <button onClick={this.handleDownloadImage}>Download</button>
    )
  }
}

Community, Please help me out.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You have to add cors configuration to your bucket properties.

Refer to this thread for more details: S3 - Access-Control-Allow-Origin Header

about 4 years ago · Santiago Trujillo Denunciar

0

there is a checklist for you.

1、If you want to edit an image, you should add the crossOrigin attribute to the img node.

2、Note, In My case. I got the cached image, and the image request doesn't send the cross origin header. So it will get an error.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda