dotvvm icon indicating copy to clipboard operation
dotvvm copied to clipboard

FileUpload image size limit

Open martindybal opened this issue 4 years ago • 3 comments

Problem:

I'm using FileUpload for uploading images to chat. I need to limit size of uploading images on mobile phones. I didn't find a way how to use less quality images for upload.

Proposal:

Add MaximumImageWidth and MaximumImageHeight and resize image before upload.

martindybal avatar Jan 11 '21 12:01 martindybal

I'd rather introduce some universal mechanism - something like specifying a file "preprocessor" that can be applied before the file is sent to the server. I can see a lot of scenarios that could benefit from this - e.g. signing the file using a client certificate before the file upload, or making some kind of validation of the file contents.

What about adding something like this?

<dot:FileUpload ...>
    <FilePreprocessors>
        <dot:ResizeImagePreprocessor Extensions="*.jpg;*.png" MaxWidth="..." />
    </FilePreprocessors>
</dot:FileUpload>

Also, the preprocessor could have a client-side and server-side part, so if the preprocessing cannot be done on the client, we can do it on the server.

tomasherceg avatar Jan 11 '21 13:01 tomasherceg

@tomasherceg sounds good!

martindybal avatar Jan 11 '21 14:01 martindybal

I think it might be a bit complicated to do the server-side processing - we will have to be able to map properties in markup to the actual class. However, on file upload we do not have access to the markup that invoked it. We could do the file processing in the postback that processes the files then, but

  • What if we want to use staticCommand
  • What if we want to disallow certain files right away
  • Relying on control doing something with viewmodel in command is generally a bad practise (it might be in a Repeater that has empty collection -> control stops existing...)

exyi avatar Jan 11 '21 18:01 exyi