@wendux 在php端使用$_FILES接收文件,还是只能接收到1个;
1:flutter 端原始参数如下:
上传文件参数:[File: '/storage/emulated/0/Customize/Wallpapers/387596.jpg', File: '/storage/emulated/0/Customize/Wallpapers/151296.jpg']
其它参数:{id: 2739, token: C6114DEE9236F025C92A20831312A697}
2:flutter dio端加入formdata原始代码如下:
FormData formData = new FormData();
//加入其它参数
if (data.length > 0) {
data.forEach((key, val) {
formData.add(key, val);
});
}
//加入图片
if (images.length > 0) {
var random = new math.Random();
List img = [];
for (int a = 0; a < images.length; a++) {
img.add(new UploadFileInfo(
images[a],
random.nextInt(10000).toString() +
'-' +
images[a].toString().substring(
images[a].toString().lastIndexOf('/') + 1,
images[a].toString().length - 1)));
}
formData.add("files", img);
}
Response response = await dio.post(url, data: formData);
return response;
3:提交数据时日志如下:
I/flutter (15669): 文件路径:File: '/storage/emulated/0/Customize/Wallpapers/387596.jpg'
I/flutter (15669): 文件名称:973-387596.jpg
I/flutter (15669): FormData:
I/flutter (15669): ----dioBoundary&Happycoding-602485224
I/flutter (15669): Content-Disposition: form-data; name="files"; filename="973-387596.jpg"
I/flutter (15669): Content-Type: text/plain
I/flutter (15669):
I/flutter (15669): 文件大小:408678
I/flutter (15669):
I/flutter (15669): 文件路径:File: '/storage/emulated/0/Customize/Wallpapers/151296.jpg'
I/flutter (15669): 文件名称:4306-151296.jpg
I/flutter (15669): FormData:
I/flutter (15669): ----dioBoundary&Happycoding-602485224
I/flutter (15669): Content-Disposition: form-data; name="files"; filename="4306-151296.jpg"
I/flutter (15669): Content-Type: text/plain
I/flutter (15669):
I/flutter (15669): 文件大小:537897
4:PHP端日志如下:
I/flutter (15669): [data]={success: 1, files: array (
I/flutter (15669): 'files' =>
I/flutter (15669): array (
I/flutter (15669): 'name' => '973-387596.jpg',
I/flutter (15669): 'type' => 'text/plain',
I/flutter (15669): 'tmp_name' => 'F:\wamp64\tmp\php1484.tmp',
I/flutter (15669): 'error' => 0,
I/flutter (15669): 'size' => 537546,
I/flutter (15669): ),
I/flutter (15669): )}
使用0.1.5版本,还是不行;