Nothing Is Validating Multipart File While Streaming Files

Already tried

request.multipart.file('avatar', {
  types: ['jpeg', 'jpg', 'png'], // I already tried -> type: ['image'] types: ['image'],
  size: "4mb"
  }, async file => {
    await Drive.put(key, file.stream)
})

.../Validators/changeAvatar.js

'use strict'

class UserChangeAvatar {
  get rules() {
    return {
      avatar: 'required|file|file_ext:png,jpg,jpeg,svg'
    }
  }
}

module.exports = UserChangeAvatar

Nothing works, the code lets you upload any type of file, like .pdf or .mp4

There’s nothing in the Adonis.js documentation talking about it either.

Package version

Version 4.1
"@adonisjs/framework": "^5.0.9"

Node.js and npm version

NODE - v10.15.0
NPM - 6.10.1

You cannot validate the file like this when streaming a file. Streaming means, that you are reading a byte at a time and then writing that somewhere else.

Which means, that at the time of streaming, there isn’t enough information to make the validation decisions and instead the consumer of the stream should do the validation.

Suggest you to read this https://github.com/substack/stream-handbook

1 Like