使用reactjs从媒体库发送文件

发布于 2025-01-17 01:25:53 字数 1641 浏览 2 评论 0原文

我有一个聊天,它是在 REACTJS + Nodejs 中完成的,一切都很完美,但我想实现一个媒体库类型功能,人们可以在其中选择系统中可用的照片,例如:

我有我上传文件并在表格中列出它们的页面。

在我发送消息的聊天页面上,当我单击附加文件按钮时,Windows 窗口会正常打开,以便可以上传和发送图像。

我希望当我单击此按钮时,将打开一个模式,并且将列出系统中可用的这些图像,并且可以在聊天中选择并发送这些图像。

列出聊天中图像的模式我能够打开它,我只是无法通过它,发送选定的图像,我不知道我是否需要回调函数或其他东西。

列出文件的页面:

Página ondemostra os arquivos

模式打开的聊天页面:

Página do chat

我希望当您单击模态的任何图像时,它会被发送到聊天室。

负责上传和发送文件的部分代码:

const handleChangeMedias = (e) => {
if (!e.target.files) {
  return;
}

const selectedMedias = Array.from(e.target.files);
setMedias(selectedMedias);  };

<input
          multiple
          type="file"
          id="upload-button"
          disabled={loading || recording || ticketStatus !== "open"}
          className={classes.uploadInput}
          onChange={handleChangeMedias}
        />
        <label htmlFor="upload-button">
          <IconButton
            aria-label="upload"
            component="span"
            onClick={handleOpenContactModal}
            disabled={loading || recording || ticketStatus !== "open"}
          >
            <AttachFileIcon className={classes.sendMessageIcons} />
          </IconButton>
        </label>

感谢 id advance !

我可以创建页面来上传文件,并且可以在聊天页面上以模式显示这些文件,现在我无法选择这些文件并将其发送到聊天。

Obs:从计算机上传和发送文件到聊天室的功能工作正常,我可以选择文件并发送。

I have a chat, it is done in REACTJS + nodejs, everything works perfectly, but I want to implement a media library type function, where the person will be able to choose the photos that are available in the system, for example:

I have a page where I upload files, and list them in a table.

On the chat page, where I send messages, when I click the attach file button, the windows window opens normally so that the image can be uploaded and sent.

I would like that when I clicked on this button, a modal would be opened and these images that are available in the system would be listed and that could be selected and sent in the chat.

The modal listing the images in the chat I was able to open it, I just can't get past it, make the selected image sent, I don't know if I would need a callback function or something.

Page where the files are listed:

Página onde mostra os arquivos

Chat page with modal open:

Página do chat

I would like that when you click on any image of the modal, it would be sent to the chat.

Part of the code responsible for uploading and sending the file:

const handleChangeMedias = (e) => {
if (!e.target.files) {
  return;
}

const selectedMedias = Array.from(e.target.files);
setMedias(selectedMedias);  };

<input
          multiple
          type="file"
          id="upload-button"
          disabled={loading || recording || ticketStatus !== "open"}
          className={classes.uploadInput}
          onChange={handleChangeMedias}
        />
        <label htmlFor="upload-button">
          <IconButton
            aria-label="upload"
            component="span"
            onClick={handleOpenContactModal}
            disabled={loading || recording || ticketStatus !== "open"}
          >
            <AttachFileIcon className={classes.sendMessageIcons} />
          </IconButton>
        </label>

Thanks id advanced !

I can create the page to upload the files and I can display these files in a modal on the chat page, now I am not able to select and send any of these files to the chat.

Obs: The functionality of uploading and sending files from the computer to the chat works correctly, I can select the file and send.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文