Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
How to iterate into FileList?

I'm creating this component that allows the user to send a single or multiple image using socket io. But I'm having this problem on how can iterate into FileList that can be use as a blob then pass into FileReader to be readAsDataURL?

Function for upload images

const handleOnUploadChat = (e) => {
    let fileArr = Array.from(e.target.files);
    setUploadImgChat(fileArr);
  };

Function to send message

const handleSendMessage = (e) => {
    e.preventDefault();

    if (newMessage) {
      const messageData = {
        conversationId: currentConversationInfo._id,
        senderId: currentAccountInfo._id,
        messageText: newMessage.messageText,
      };

      // dispatch(registerMessage(messageData));

      socket?.emit('sendMessage', {
        senderId: currentAccountInfo,
        receiverId: currentConversationInfo.members.find(
          (id) => id !== currentAccountInfo._id
        ),
        message: newMessage.messageText,
        imagesFilename: uploadImgChat.map((file) => file.name),
        imagesFileType: uploadImgChat.map((file) => file.type),
        images: uploadImgChat.map((file) => file),
      });


      setCurrentMessage((currentMessage) => [
        ...currentMessage,
        { senderId: currentAccountInfo, messageText: newMessage.messageText },
      ]);
    }
  };

Function get message

socket.on('getMessage', (data) => {
          const blob = new Blob([data.images], { type: data.imagesFileType });
          const reader = new FileReader();
          reader.readAsDataURL(blob);
          reader.onload = function () {
            setReceiveImg(reader.result);
          };

          setArrivalMessage({
            senderId: data.accountId,
            messageText: data.message,
            messageImg: receiveImg,
            createdAt: Date.now(),
          });
        });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda