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

248
Vistas
how can I save image and video file in redux

I am preparing a form that has fields to allow the user to post his picture and a video about her/him(self). To post a picture I prepared a component based on input type file, but to upload a video I have used React Dropzone. Now I want to save this to redux, however when I try to do that redux is complaining that it is the non-serializable item, and when I put it into JSON.Stringify() redux is getting an empty object. What would be the optimal solution for that, I have to store it somewhere in-state, should it be a local state created in this step of the form (fortunately it is the last one) however if the user would like to go back to any previous step and come back this data will be lost

Please advise, the dropzone component is below, onResult is just a handler that takes the value and dispatches an action to redux

import React, { useCallback, useState } from "react";
import { useDropzone } from "react-dropzone";

export const FileDropzone = ({ onResult, fileTypes, maxFiles }) => {
    const [progress, setProgress] = useState(0);
    const [error, setError] = useState(false);

    const onDrop = useCallback(acceptedFiles => {
        acceptedFiles.forEach(file => {
            const reader = new FileReader();
            reader.onerror = () => setError(true);
            reader.onprogress = data => {
                if (data.lengthComputable) {
                    var progress = parseInt(
                        (data.loaded / data.total) * 100,
                        10
                    );
                    setProgress(progress);
                }
            };
            reader.onloadend = () => onResult(reader.result);
            reader.readAsArrayBuffer(file);
        });
    }, []);
    const { getRootProps, getInputProps } = useDropzone({
        onDrop,
        maxFiles,
        accept: fileTypes
    });

    return (
        <>
            <div
                className={`border border-${
                    error ? "danger" : "light"
                } rounded d-flex justify-content-center align-items-center hpx-100`}
                {...getRootProps()}
            >
                <input {...getInputProps()} />
                <p>Proszę kliknąć, lub upuścić wybrany plik.</p>
            </div>
            <div
                className="bg-primary hpx-20 mt-1"
                style={{ width: `${progress}%` }}
            ></div>
        </>
    );
};

Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think your best bet would be to convert the file to Base64.

Please check How to convert file to base64 in JavaScript?

and

https://github.com/reduxjs/redux/issues/2276

about 4 years ago · Juan Pablo Isaza 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