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)
- Access response data type <T> in Interceptor. HOT 5
- SOCKS5 PROXY SUPPORT HOT 1
- Dio on Windows : Invalid media type: expected no more input. HOT 3
- I cannot set a content-type of a form-data field HOT 5
- DioException (DioException [bad response]: This exception was thrown because the response has a status code of 401 and RequestOptions.validateStatus was configured to throw for this status code. HOT 3
- The connection errored: Connection refused This indicates an error which most likely cannot be solved by the library. HOT 2
- [Web] ERROR_TYPE: DioExceptionType.connectionError HOT 2
- Flutter web deployment HOT 1
- [Dio native adapter] proxy HOT 2
- Exception has occurred. DioException (DioException [bad response]: This exception was thrown because the response has a status code of 401 and RequestOptions.validateStatus was configured to throw for this status code. The status code of 401 has the following meaning: "Client error - the request contains bad syntax or cannot be fulfilled" Read more about status codes at https://developer.mozilla.org/en-US/docs/Web/HTTP/Status In order to resolve this exception you typically have either to verify and fix your request code or you have to fix the server code. ) HOT 1
- error 404 when trying to download a file. HOT 3
- How to mock Dio.interceptors.add when write unit test? HOT 1
- Conditionally allows relative path for `baseUrl` HOT 11
- Need a way to catch DioException [request cancelled] from the caller code HOT 3
- 有没有大佬帮我看看我的代码有什么问题,handler.resolve(res) 后,原始请求返回值一直为空,不知道为什么? HOT 1
- I don't know where the problem is with my code. After handler.reslove(res), the return value of the original request is always empty. HOT 3
- [Flutter Web] dio.get() sends options. HOT 1
- How to use handler.reject in onError of QueuedInterceptor HOT 1
- [native_dio_adapter] Exception fetching LoggerImpl class HOT 4
- http请求头不标准,大小写全部错误 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.