如何将图像从Java客户端上传到Node.js

时间:2019-06-22 14:26:14

标签: java node.js

我正在尝试将图像从Java客户端发送到Node服务器,但是nodejs没有得到任何文件。我在Java中使用Apache MultipartEntityBuilder。 我用过multer和busBoy,但两者都没有用 Java代码:

String name = String.valueOf((new Date()).getTime());
            String extension = filePath.substring(filePath.lastIndexOf("."));
            CloseableHttpClient client = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost("http://localhost:3000/gallery/upload");

            MultipartEntityBuilder builder = MultipartEntityBuilder.create();

            builder.addBinaryBody("uploadFile",new File(filePath),
                    ContentType.APPLICATION_OCTET_STREAM,name+extension);
            HttpEntity multipart = builder.build();
            httpPost.setEntity(multipart);

            CloseableHttpResponse response = client.execute(httpPost);
            client.close();

Node JS没有看到任何文件

multer = require('multer'),
        uploadFile = multer({dest: '../images/public/images/UploadedImages/'});
    router.post('/upload',uploadFile.single('uploadFile'),(req,res) =>{
        console.log(req.body.file);
        res.sendStatus(200);
    });

0 个答案:

没有答案