Flutter,将照片上传到我的api时遇到问题

时间:2020-02-29 06:41:27

标签: express flutter camera multipartform-data dio

我正在测试通过相机从flutter应用程序到我的express api的发送,但是当我这样做时,我总是得到一个空表,我做错了吗?

这是我的代码:

flutter应用程序:

final filename = '${DateTime.now()}.png';
final path = join((await getTemporaryDirectory()).path, filename);
await cameraController.takePicture(path);

FormData formData = new FormData.fromMap({
  "file": MultipartFile.fromFile(path, filename: filename)
});

await dio.post('api_url', data: formData)
.then((value) => print)
.catchError((err) => print);

我的api:

 async ocr(req, res): Promise<void> {
    console.log(req.files);
    return res.send('ok')
}

0 个答案:

没有答案