简体   繁体   English

React.JS:如何制作存储在公共文件夹中的图像的表单数据

[英]React.JS: how can I make a form data of an image stored in public folder

there's some images in the public folder and when a user chooses one of them, I have to post the image to the server, and it has to be the image file itself and not its name or anything else, the problem is that when I import the image like this:公共文件夹中有一些图像,当用户选择其中一个时,我必须将图像发布到服务器,它必须是图像文件本身而不是它的名称或其他任何东西,问题是当我导入时像这样的图像:

import file1 from "../../../public/static/images/1.png"

and then use this code:然后使用此代码:

const data = new FormData();
data.append("useChoice", file1);

the result will be empty or not a file.结果将为空或不是文件。 how should I handle it?我应该如何处理?

instead of load image and send it to client, then user send it to server again.而不是加载图像并将其发送到客户端,然后用户再次将其发送到服务器。 u should use link point to those images.您应该使用指向这些图像的链接点。 If u must do it that way, try https://webpack.js.org/guides/asset-management/#loading-images如果您必须这样做,请尝试https://webpack.js.org/guides/asset-management/#loading-images

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM