使用reactjs从媒体库发送文件
我有一个聊天,它是在 REACTJS + Nodejs 中完成的,一切都很完美,但我想实现一个媒体库类型功能,人们可以在其中选择系统中可用的照片,例如:
我有我上传文件并在表格中列出它们的页面。
在我发送消息的聊天页面上,当我单击附加文件按钮时,Windows 窗口会正常打开,以便可以上传和发送图像。
我希望当我单击此按钮时,将打开一个模式,并且将列出系统中可用的这些图像,并且可以在聊天中选择并发送这些图像。
列出聊天中图像的模式我能够打开它,我只是无法通过它,发送选定的图像,我不知道我是否需要回调函数或其他东西。
列出文件的页面:
模式打开的聊天页面:
我希望当您单击模态的任何图像时,它会被发送到聊天室。
负责上传和发送文件的部分代码:
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:
Chat page with modal open:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论