Topic: image size limit

I need script for make image size limit when upload to database..
for example image size >= 100 kb and <= 500 kb

Thanks you

Re: image size limit

Hello MVD Family... Anyone can help me??

Re: image size limit

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
   Size,kb: Integer;
begin
   Size := GetFileSize('YourImageFile.png');
   kb := Round(Size/1024);
   If (kb >= 100) and (kb <= 500) then
      ShowMessage('File size is in range')
     else
      ShowMessage('File size is not in range');
end;

Re: image size limit

Thanks ehwagner for your advice,
but I don,t know how implementation to my project
can you help me again?
see my attachment

Post's attachments

Attachment icon picturesize.rar 293.99 kb, 243 downloads since 2021-03-21 

Re: image size limit

First, your project is not really a working application and even after my changes it still is not. No insert feature except upon opening the app and not sure why the two save buttons. One of them does not really do anything.


Second, the DbImage component buttons are not trappable. At least I am not aware of anything to intercept the events on the open button. Therefore, as a possible solution to your needs, I hid the component buttons and created my own OPEN button (visible when you mouseover the image component). The check for the size of the file occurs when selecting an image in the dialog. If the file size is within your size range then it will display otherwise it will present an error message and not display. The BUTTONSAVE button is the real save button to save the record.


I changed your DbImage component from StoreFile to LinkFile. I highly recommend storing images outside your database. It can dramatically slow your app especially if you have a lot of records holding images.


Hope this helps.

Post's attachments

Attachment icon picturesize revised.zip 963.51 kb, 295 downloads since 2021-03-22 

Re: image size limit

thank you ehwagner,
thanks for your solution and advice ... project worked well .. awesome.

If photos or files are saved in a folder with linkFile, how do I backup and restore the data without having to copy from the main folder of the application?

Re: image size limit

Not sure I understand your question. Are you asking about backing up and restoring the folder containing your photos?

Re: image size limit

Yes i am
I  ask you about backing up and restoring the folder containing my photos.
I am sorry maybe this is stupid question..

Re: image size limit

If you are the one who is managing the photos, you can simply use Windows Copy and Paste to backup your photo folder. But if you want to do it within MVD, you can use the DirectoryCopy function to do the same. See attached example project. In this example the backup folder is inside the application folder. I do not recommend this. Your backup folder should be in another location, preferably on another media.

Post's attachments

Attachment icon Copy Folder.zip 778.05 kb, 282 downloads since 2021-03-24 

Re: image size limit

Ehwagner, Tank you verry much...
I have solution from you... awesome
the project is work well...

11 (edited by agusecc 2021-03-25 11:43:55)

Re: image size limit

can you help me again?
how script backup dan restore the folder to another place out of aplication?
Thanks you

12 (edited by ehwagner 2021-03-25 17:24:18)

Re: image size limit

Unfortunately I can't give a specific answer because I do not know your situation or computer setup. I don't know if you are creating this project for yourself or for a business, friend or someone else. All I can do is explain the syntax of the DirectoryCopy command. You will need to know the various paths to your users' storage devices and place those paths into the command.

DirectoryCopy('From Path','To Path');

The 'From Path' is the current location of your photos. This is the path where your photos are located for your app.


The 'To Path' is the path to the location you want to store your backup. This can be a path to an SD card, USB drive, CD, external hard drive, a server drive, a Cloud drive, etc. You just type the path inside the quotes.


So you can either hard code the path inside the quotes, as mentioned above, or make a settings file and then have the user select the backup path and store it in your settings file. Then the DirectoryCopy command can be filled in with the value in your settings file. This way if a user wants to change the backup location, you will not need to change the program to accommodate. This may be a little more advanced for you, but the ability is there.

Re: image size limit

ehwagner, Thank you for the explanation you have given I began to understand how to do it ..
may God bless you always