0

I use Laravel and Behat and Mink for behavior testing and I have issue in one of the scenarios for testing image uploading.

My Scenario :

Scenario: Upload image
    When I attach the file "/images/pic.png" to "img"
    And I press "Upload"
    Then I should see "The image uploaded successfully"

And I have a validation in my controller like this :

$this->validate($this->request, [
    'img' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:1024',
]);

When I print the response, the uploaded file has application/octet-stream mime type. So the validation fails.

How can I fix it?


dd(request()) :

array:3 [
  "img" => Illuminate\Http\UploadedFile {#4871
    -test: false
    -originalName: "pic.png"
    -mimeType: "application/octet-stream"
    -size: "55916"
    -error: 0
    path: "/tmp"
    filename: "619efa338a3efe391405e269b61543bfb3b88322.png"
    basename: "619efa338a3efe391405e269b61543bfb3b88322.png"
    pathname: "/tmp/619efa338a3efe391405e269b61543bfb3b88322.png"
    extension: "png"
    realPath: "/tmp/619efa338a3efe391405e269b61543bfb3b88322.png"
    aTime: 2017-07-11 05:03:25
    mTime: 2017-07-11 05:03:25
    cTime: 2017-07-11 05:03:25
    inode: 538181
    size: 55916
    perms: 0100644
    owner: 1000
    group: 1000
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
  }
]
Misagh Laghaei
  • 1,293
  • 1
  • 14
  • 26
  • As docs says, for validation if you add `image`, The file under validation must be an image (jpeg, png, bmp, gif, or svg) so why are you adding mime type validation after that ? – Sagar Gautam Jul 11 '17 at 05:25
  • Yes it is correct. But the error will remain because of that `image` rule and accepted mime types. My problem is here that the mime type of uploaded file is `application/octet-stream` and the validation fails because of that `image` rule or mime types. – Misagh Laghaei Jul 11 '17 at 07:13
  • see here this might help you https://stackoverflow.com/questions/20508788/do-i-need-content-type-application-octet-stream-for-file-download – Sagar Gautam Jul 11 '17 at 07:39
  • Thanks. but the problem is still there. – Misagh Laghaei Jul 11 '17 at 07:49

0 Answers0