Comments (14)
In next version, will support uploading files array .
from dio.
Supported! please update dio to 0.1.3 .
Examples
FormData formData = new FormData.from({
"name": "wendux",
"age": 25,
"file1": new UploadFileInfo(new File("./upload.txt"), "upload1.txt"),
// Pass multiple files within an Array
"files": [
new UploadFileInfo(new File("./example/upload.txt"), "upload.txt"),
new UploadFileInfo(new File("./example/upload.txt"), "upload.txt")
]
});
from dio.
确实需要乐意上传图片数组的功能
from dio.
@wendux When will next version release?
from dio.
HI,更新到 0.1.5 的版本,发现上传多个文件,接收端依旧只能接收到第一个文件,日志如下:
I/flutter (25921): {id: 2739, token: C6114DEE9236F025C92A20831312A697, files: [Instance of 'UploadFileInfo', Instance of 'UploadFileInfo']}
I/flutter (25921): Instance of 'UploadFileInfo'
I/flutter (25921): Instance of 'UploadFileInfo'
I/flutter (25921): 787-318318.jpg [第一个文件]
I/flutter (25921): 1260-387107.jpg [第二个文件]
I/flutter (25921): 583814
I/flutter (25921): [data]={success: 1, files: array (
I/flutter (25921): 0 =>
I/flutter (25921): Phalcon\Http\Request\File::__set_state(array(
I/flutter (25921): '_name' => '787-318318.jpg',
I/flutter (25921): '_tmp' => 'F:\wamp64\tmp\phpC18.tmp',
I/flutter (25921): '_size' => 583420,
I/flutter (25921): '_type' => 'text/plain',
I/flutter (25921): '_realType' => NULL,
I/flutter (25921): '_error' => 0,
I/flutter (25921): '_key' => 'files',
I/flutter (25921): '_extension' => 'jpg',
I/flutter (25921): )),
I/flutter (25921): )}
其中 583814 看起来之包含了第一张图片的尺寸,缺少第二张图片的尺寸
盼回复,谢谢。
from dio.
@jingjianbing000 你用php原生的全局魔术产量file取一下,可能是你使用的框架不支持(laravel 就不支持),dio多文件上传测试就是用php的。
from dio.
0.12的时候试了下也不行,go后端,我还是用官方http的,就是body不支持中文值,要改下
from dio.
@asmh1989 0.0.12上传文件有问题,然后就紧急修复了,你可以用最新版试试,如果最新版还不行的话, 麻烦贴一下报错信息。
from dio.
@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<dynamic> 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版本,还是不行;
from dio.
@jingjianbing000 php下传数组文件时,key要带上"[]", 下面是我在本地测试的代码,是成功的:
FormData formData = new FormData.from(<String,dynamic>{
"files[]":[
new UploadFileInfo(new File("./example/upload.txt"), "upload.txt"),
new UploadFileInfo(new File("./example/upload.txt"), "uploadc.txt")
]
});
php 端调用var_dump($_FILES)
打印的日志:
array(1) {
["files"]=>
array(5) {
["name"]=>
array(2) {
[0]=>
string(10) "upload.txt"
[1]=>
string(11) "uploadc.txt"
}
["type"]=>
array(2) {
[0]=>
string(10) "text/plain"
[1]=>
string(10) "text/plain"
}
["tmp_name"]=>
array(2) {
[0]=>
string(45) "/Applications/XAMPP/xamppfiles/temp/phpK7829F"
[1]=>
string(45) "/Applications/XAMPP/xamppfiles/temp/php34xFNW"
}
["error"]=>
array(2) {
[0]=>
int(0)
[1]=>
int(0)
}
["size"]=>
array(2) {
[0]=>
int(39)
[1]=>
int(40)
}
}
}
可见两个文件接收到了。
from dio.
@wendux 0.1.6 go 后端还是只能识别 一张, 官方http库没问题
from dio.
@wendux 我对比官方http中的代码, 发现
https://github.com/dart-lang/http/blob/0.11.x/lib/src/multipart_request.dart#L110
在每个文件数据后应该加上\r\n
我这边测试通过
from dio.
@asmh1989 你是怎么改的?
from dio.
已经提交了个pr
from dio.
Related Issues (20)
- Error Dio flutter web HOT 1
- upload file send timeout
- Header is out of order HOT 3
- `ResponseType.stream` is not working on web. HOT 1
- [🔔 Dio] sendTimeout cannot be used without a request body to send HOT 2
- `Transformer.isJsonMimeType` throws format exceptions without caught
- onError is not returning any error HOT 3
- Error when uploading image using MultipartFile.fromBytes in version 5.4.3+1 HOT 1
- 为什么dio的fromMap会将MultipartFile自动放入files字段中 HOT 1
- Error: The method 'debugLog' isn't defined for the class 'BrowserHttpClientAdapter'. HOT 1
- Version 5.5.0 brakes the web build HOT 1
- Is it now possible to use DIO / dio_web_adapter with Web/WASM? HOT 41
- Dio 5.5 broke compilation for WASM HOT 6
- ResponseType.stream returns responce all at once on Web HOT 1
- Date header not parsed correctly HOT 1
- set proxy for BrowserHttpClientAdapter HOT 1
- Dio fetch can't catch error HOT 1
- Return the app to the desktop, then switch to Wi Fi in the system. After switching to Wi Fi, click on the desktop app icon to enter the app. At this point, there is an exception when sending network requests. This is highly likely to occur on Ios HOT 5
- when using "handler.reject(error);" in onError of interceptors, I cannot DioException in .catchError(), but find it in .then(). HOT 1
- Dio cannot connect to the Internet after VPN is enabled on iOS devices HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dio.