Code Monkey home page Code Monkey logo

activestorage-validator's People

Contributors

aki77 avatar brunoocasali avatar cseelus avatar dependabot[bot] avatar eimermusic avatar oscartzgz avatar petergoldstein avatar sebkeller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

activestorage-validator's Issues

Add filename to error message

Since active storage supports has_many_attached, it is challenging to identify which file is not of the given content type. How can we add a filename from the blob to the error message?

Help with .xlsm files pls

Hello!

I've been having problems to upload an .xlsm file (Excel with macros) I'm using this mime-type application/vnd.ms-excel.sheet.macroEnabled.12 I got it from here and also here. However, I keep receiving a model error {upload_fail: {file: ["is not a valid file format"]}} and my gem usage is standard i guess.

validates :file, blob: { content_type: [ 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'application/vnd.ms-excel.sheet.macroEnabled.12', 'application/vnd.ms-excel.template.macroEnabled.12', 'application/vnd.ms-excel.addin.macroEnabled.12', 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' ], size_range: 0..700.megabytes }

*.ts can't pass on validate of video when i using direct upload.

i can't upload .ts extension file. (.ts is video file extension)
this *.ts can't pass on validate when i using direct upload.

but this is working well passing validate when not using direct upload.
i use below code with content_type: :video

class Encode < ApplicationRecord
  validates :file, presence: true, blob: { content_type: :video } # supported options: :image, :audio, :video, :text
end

x1wins/CW-OVP#5

Unknown validator: 'PrecenceValidator'

Above Exception is raised when you write this line
validates :image, precence: true, blob: { content_type: ['image/png', 'image/jpeg'], size_range: 1..5.megabytes }
You must have to changed it to presence

Content type Question

Hello,

I am wondering if the content type is enough to validate the file type. Content type is given by the user, which means they can give whatever they want.

Wouldn't it be useful to validate the extension of the file?

No default error messages for content_type and max_size_error

The current default informs the user to add a locale entry for the specific attribute errors.
I have created a fix where I have default error messages instead.

en:
  activerecord:
    errors:
      messages:
        content_type: "is not a valid file format"
        max_size_error: "is not within valid size range"

I cannot push my branch up to your repo to create a PR, you need to probably allow that before anyone can contribute.

Doesn't work with activeadmin file upload

Hi,

Thanks for making this gem. I am working on using ActiveStorage for storing files uploaded from activeadmin's formtastic inputs. However, this gem seems not to be working with ActiveAdmin.

Although it does raise errors after the file with invalid extension was uploaded, the file is still stored in the storage.

Version:

  • Rails 5.2.1
  • Activeadmin 1.3.1
  • activestorage-validator 0.1.0
  • has_one_attached :file

Compatibility with Rails 6

Currently installing ActiveStorage Validator with Rails 6 (Beta 2) fails with activestorage-validator (~> 0.1.2) was resolved to 0.1.2, which depends on rails (~> 5.2.0).

Is there anything blocking the use with Rails 6 or just not tested yet?

Validation for image dimensions?

Hi there,

Is there a validation option for dimensions on image file types? e.g. max_size 1000px, min_size 100px, etc? If not, could I add this as a contribution to this project?

Cheers,

Ian

File Type Validation does not check if extension and MIME Type match

I have tested the validation by changing the extension of a file. For example I took a file called 'test.pdf' and changed it to 'test.docx'. I validate as follows:

validates :file, presence: true, blob: { content_type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'}

This passes. Shouldn't the validation fail since this is really a pdf and not a docx document?

Feature request: validate if an uploaded file is an image without depending on a spoof'able content-type

Hi,

The content type of a file can be spoofed which could allow someone to upload an executable file with the content type of jpg. This could allow your app to throw exceptions if it tries to perform image operations on an executable.

Usually the way to determine if something is an image is to read in the first few bytes of the file looking for a specific sequence of bytes. I haven't gotten to implementing something like this with Ruby but with Python the imghdr standard library module has a imghr.what function to call which lets you pass in a byte stream or file and it'll return back what format the file is in (jpg, png, etc.).

It's nice to be able to do this on a byte stream instead of a file because if you're uploading things as a stream you can determine if it's an image or not very quickly without uploading the entire file beforehand.

I suppose this would involve introducing a new validator that lets you whitelist a set of valid image formats and it could default to the common case of jpg, jpeg, png and webp. What do you think? Maybe this could be done using the Vips library or the image_processing gem since this is a requirement of Active Storage?

has_many_attached validates the size of each individual attachment, correct?

Hi,

It was not absolutely sure this gem validated the individual sizes of each file in a has_many_attached or if it validated the size of all files combined in the association. I could kind-of see a use for both.

I checked the specs. They did not explicitly validate the size in a many relationship with multiple files.

I read the implementation to mean that it in fact does treat each file individually and does not do combined size validation.

I did figure it out (I think) but it might be useful to clarify this in the README?

Thanks for a great gem, btw.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.