代码之家  ›  专栏  ›  技术社区  ›  Atnaize

Laravel:用真实文件测试post

  •  0
  • Atnaize  · 技术社区  · 7 年前

    我在用拉维 5.6 post 需要 file . 所以我写的

    $file = new \Illuminate\Http\UploadedFile(base_path() . '/tests/samples/Cylinder.stl', 'Cylinder.stl');
    
    $response = $this->post( route('attachments.store' ) , [
        'file' => $file,
        'attachable_id' => $this->threedviews->id,
        'attachable_type' => 'App\ThreeDView',
    ]);
    

    dd( $this->app['session.store'] ) ,我明白了

    #bags: array:1 [
            "default" => Illuminate\Support\MessageBag {#1198
              #messages: array:1 [
                "file" => array:1 [
                  0 => "The file failed to upload."
                ]
              ]
              #format: ":message"
            }
          ]
    

    当我手动使用表格时,一切都很好。 $file 看起来很奇怪

    Illuminate\Http\UploadedFile {#43
      -test: false
      -originalName: "Cylinder.stl"
      -mimeType: "application/octet-stream"
      -error: 0
      ...
    }
    

    test 旗子被设为假,应该是这样吗?

    0 回复  |  直到 7 年前