vine icon indicating copy to clipboard operation
vine copied to clipboard

Discussion for a new feature - Validating files

Open Edgar200021 opened this issue 9 months ago • 9 comments

Hello, I understand correctly in vine there is no file validation functionality ? Or did I miss something ?

Edgar200021 avatar Mar 19 '25 06:03 Edgar200021

@thetutlage , would you accept a PR for this feature??? I can implement it if it would be accepted

lubiah avatar Apr 15 '25 00:04 lubiah

@thetutlage any response?

lubiah avatar Apr 17 '25 14:04 lubiah

Hello @lubiah

Can you please share which Files will be validated by the File schema. It will be great if you can write a small proposal

thetutlage avatar Apr 26 '25 19:04 thetutlage

Hi @thetutlage , here's a small proposal

Proposal: Introduce File Validation for VineJS

Objective Add validation functionality to handle File instances in VineJS, enabling developers to validate file attributes like type, size, and extension.

Proposed Validation Rules

  1. file.maxSize: to validate the max size of a file instance
  2. file.minSize: to validate the min size of a file instance
  3. file.mimetypes([]), validates and checks if the instance mimetype is included in the array

Currently, there's no way of validating files in web forms and this would really help us to do that.

** References of the file validator in other validation libraries**

  1. Valibot
  2. Zod

lubiah avatar Apr 27 '25 01:04 lubiah

Where does the File class comes from? Remember VineJS works with Nodejs only and not in the browser

thetutlage avatar Apr 27 '25 03:04 thetutlage

Hello, I don't know if I'm mistaken but the file class is also present in NodeJS. Here's a link to it in the NodeJS docs. In my project, I'm currently validating the files from formData in nodejs and it's working

lubiah avatar Apr 27 '25 09:04 lubiah

I see. Yup, it will be a nice addition to have. We will need a new schema type for this. Lemme know if you are up for the PR?

thetutlage avatar May 05 '25 10:05 thetutlage

I've already implemented it in my project. I'd be glad if you assign this issue to me. I'm ready to work on it

lubiah avatar May 05 '25 14:05 lubiah

@thetutlage , can you kindly review the pull request

lubiah avatar May 18 '25 21:05 lubiah