Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

70
Vistas
Rendering multiple image blob ulrs using react result in corrupted images

I'm trying to build an app that takes an image file as input, posts it to the server, and receives a styled image as blob URL. The problem is that some of the received images are sometimes corrupted. There is no pattern here and some of them are randomly corrupted. And sometimes it works fine with no corrupted images. Here are the relevant code snippets. I'm using django-rest framework for the backend.

var styled_images = []

function StyleTransferCarousel() {
    const [styledImages, setStyledImages] = useState([])
    const [styled, setStyled] = useState(false)

    // this function gets the image blob from server
    const getStyledImage = async (model) => {
            var formData = new FormData()
            ...
            try {
                const { data } = await axios.post('/style_transfer/stylev2/', formData, config)
                return data
            } catch (error) {...}
        }
    
    // this function gets the image blob untill the size of image list is equal to available models and re-renders
    async function getStyledImages() {
            var styledImageDict = {}
            for (let i = 0; i < models.length; i++) {
                var model_i = models[i]
                var data = getStyledImage(model_i)
                data.then(data => {
                    styledImageDict = {
                        image: "data:image/png;base64," + data.image,
                        model: models[i]
                    }
                    styled_images = styled_images.concat([styledImageDict])
                    if (styled_images.length !== models.length) {
                        setLoader(false)
                        setStyledImages(styled_images) //react hook
                    }
                })
            }

    }
    
// this is called once, if images are not styled
    useEffect(() => {
        if (models.length !== 0 && !styled) {
            //styled = true
            setStyled(true)
            getStyledImages()
            setLoader(true)
        }
    }, [models])
...
}

The images setStyledImages object are rendered. Some examples of corrupted images are below: enter image description here enter image description here

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.