Validating files before upload - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: Validating files before upload (/thread-15.html) Pages:
1
2
|
Validating files before upload - davenovo - 03-14-2018 Hello, How do I validate files before they are uploaded. i.e. if I want to only allow files that have the word 'banana' somewhere in the filename, how do I check that before all the files are uploaded? If the validation fails, how do I then cancel the upload? If multiple files are selected, and only one fails validation, can I just abort the upload of that one file? RE: Validating files before upload - davenovo - 03-16-2018 any advice? RE: Validating files before upload - DanielFields - 03-16-2018 Here is some old code that I tried along those lines. It worked in my simple testing. Code: private RE: Validating files before upload - davenovo - 03-18-2018 Hi Daniel, Thank for the help. But that is not exactly what I wanted. In the case above, you are setting FileRejected to True AFTER the file is uploaded. Why go through the bother of letting them upload a 100 Mb file if I know I am going to reject it. For example, if I know I only allow files with the word "apple" somewhere in the filename, I should be able to abort the file upload before it starts if the filename does not contain the word apple. RE: Validating files before upload - kudzu - 03-19-2018 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file RE: Validating files before upload - davenovo - 03-19-2018 Hello, While that link shows a bunch of javascript, I am not clear how that ties into the events that you expose. I presume I have to do something in the OnAsyncSelectFile, I just dont know to a) get the filename currently "selected". Is that in the EventParms b) how to signal to abort that file RE: Validating files before upload - DanielFields - 03-19-2018 (03-19-2018, 05:57 PM)davenovo Wrote: You can use the MaxFileSize property to prevent uploading of large files. CGDevTools has an uploader that allows you to specify permitted file extensions. I'm not sure if it supports a file mask, but you can give it a try. RE: Validating files before upload - Alexandre Machado - 03-19-2018 (03-18-2018, 06:00 PM)davenovo Wrote: Hi Daniel, OnAsyncSelectFile event happens BEFORE the file has been uploaded. It occurs immediately after anything has been selected at browser side, but before any update takes place. This is the exact moment to validate anything. Besides that AllowedExtensions, MinFileSize and MaxFileSize can limit the possible extensions and file size, without any communication to the server. RE: Validating files before upload - davenovo - 03-19-2018 Ok, so please, just tell me, if I use OnAsyncSelectFile, how do I abort the upload of the file if I decide to do so? I would expect the OnAsyncSelectFile to have a parameter FileName:string and procedure OnAsyncSelectFile(const aFileName:string; var aAllowUpload:boolean) However, since that is not there, can you tell me how I tell the component to stop uploading that file. Please answer the following two questions that I have been asking a) get the filename current file that is triggering the OnAsyncSelectFile. Is that in the EventParms? b) how to signal to abort the upload of that file RE: Validating files before upload - Jose Nilton Pace - 03-20-2018 Hi, you can try this in 2 steps. In Object Inspect, set AutoUpload := False; Put a button to Select file: Code: procedure TIWForm1.IWButton1_SelectAsyncClick(Sender: TObject; EventParams: TStringList); Another button to upload the file after you tested the name: Code: procedure TIWForm1.IWButton2_SelectAsyncClick(Sender: TObject; EventParams: TStringList); |