通过axios post发送嵌套的Multipart / FormData和Blob

时间:2018-05-25 15:08:58

标签: javascript multipartform-data form-data

我无法创建嵌套的formData()。

我的目标是获得:

array:3 [
  "table" => "food"
  "id" => "1"
  "media" => array:2 [
     0 => array:1 [
        "url" => "https://picsum.photos/400/400"
         ]
     1 => array:1 [
        "image" => UploadedFile { ... }
         ]
   ]
]

我尝试使用该软件包:" object-to-formdata",但它只是不喜欢工作我得到:

array:3 [
  "table" => "food"
  "id" => "1"
  "media" => array:2 [
     0 => array:1 [
        "url" => "https://picsum.photos/400/400"
        "image" => UploadedFile {#593} //it should be in 1 =>
         ]
   ]
]

我无法使用

media.append('media[]', {url: "https://picsum.photos/400/400"});

它无法读取文件,我得到类似[Object Object]

的内容

我想发送的对象非常简单:

let obj = {
   table: 'food',
   id: this.food.id,
   media: [
         {url: "https://picsum.photos/400/400"},
         {image: Blob},
         {url: "https://picsum.photos/200/400"},
         ....
      ]
};

0 个答案:

没有答案