Giter Site home page Giter Site logo

Comments (14)

wendux avatar wendux commented on July 30, 2024 3

In next version, will support uploading files array .

from dio.

wendux avatar wendux commented on July 30, 2024 3

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")
    ]
});

:octocat: From gitme Android

from dio.

keluokeda avatar keluokeda commented on July 30, 2024

确实需要乐意上传图片数组的功能

from dio.

lucasjinreal avatar lucasjinreal commented on July 30, 2024

@wendux When will next version release?

from dio.

jingjianbing000 avatar jingjianbing000 commented on July 30, 2024

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.

wendux avatar wendux commented on July 30, 2024

@jingjianbing000 你用php原生的全局魔术产量file取一下,可能是你使用的框架不支持(laravel 就不支持),dio多文件上传测试就是用php的。

:octocat: From gitme Android

from dio.

asmh1989 avatar asmh1989 commented on July 30, 2024

0.12的时候试了下也不行,go后端,我还是用官方http的,就是body不支持中文值,要改下

from dio.

wendux avatar wendux commented on July 30, 2024

@asmh1989 0.0.12上传文件有问题,然后就紧急修复了,你可以用最新版试试,如果最新版还不行的话, 麻烦贴一下报错信息。

:octocat: From gitme Android

from dio.

jingjianbing000 avatar jingjianbing000 commented on July 30, 2024

@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.

wendux avatar wendux commented on July 30, 2024

@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.

asmh1989 avatar asmh1989 commented on July 30, 2024

@wendux 0.1.6 go 后端还是只能识别 一张, 官方http库没问题

from dio.

asmh1989 avatar asmh1989 commented on July 30, 2024

@wendux 我对比官方http中的代码, 发现

https://github.com/dart-lang/http/blob/0.11.x/lib/src/multipart_request.dart#L110
在每个文件数据后应该加上 \r\n

我这边测试通过

from dio.

wendux avatar wendux commented on July 30, 2024

@asmh1989 你是怎么改的?

:octocat: From gitme Android

from dio.

asmh1989 avatar asmh1989 commented on July 30, 2024

已经提交了个pr

from dio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.