我正在尝试通过 Flutter Web 将图像上传到 Strapi。我知道(从此链接)我需要使用 FormData 来执行此操作。我研究了很多方法来做到这一点,我偶然发现了Dio,当然还有Http。
两种解决方案都给了我错误:
Unsupported operation: MultipartFile is only supported where dart:io is available.
我试过这段代码:
var request = new http.MultipartRequest("POST", Uri.parse(url));
request.files.add(
await http.MultipartFile.fromPath(
"files",
imageFilePath,
),
);
request.send().then((response) {
if (response.statusCode == 200) print("Uploaded!");
print(response.statusCode);
}).catchError((e) => print(e));
正如这里建议的那样。
当我使用MultipartFile.fromBytes(...)
.
我只是想上传一个文件,因此我假设我的正文应该只包含 FormData ,正如Strapi 的文档files
中提到的那样。