CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Extract file name, extension and size after selecting file

by Lynkin » 28 Apr 2014 14:41

Hello,

I have a form with 3 fields that will store the FILE NAME, EXTENSION and SIZE of the file. I have this form done on Delphi and now i need to rebuild it using CGDevTools. I'm using the "FileUpload" component to select files but now i need to get those 3 options and store them into my fields. Anyone willing to help me out with this?

editFile_Name (name of the file)
editFile_Ext (extension of the file)
editFile_Size (size of the file)

Thanks in advance!
Lynkin
 
Posts: 26
Joined: 24 Apr 2014 19:53

by Jorge Sousa » 28 Apr 2014 15:11

Hi

If you check the demo source code, in the fileupload frame, you'll see that we use the event JQFileUploadOptions.OnUpload, and access to the property FileNames to get the name,

you'll have to use Delphi methods to get the

FileName: ExtractFileName, and Ext: ExtractFileExt and GetFileSize1 (eg), passing the filename with full path to where the uploaded files are, if JQFileUploadOptions.UploadPath is left empty, WebApplication.UserCacheDir is used.

function GetFileSize1(const AFileName: TFileName): Int64;
var
SearchRec: TSearchRec;
begin
if FindFirst(AFileName, faAnyFile, SearchRec) = 0 then
begin
Result := SearchRec.Size;
System.SysUtils.FindClose(SearchRec);
end
else
begin
Result:= -1;
end;
end;
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by Lynkin » 02 May 2014 18:51

I tried to understand what you said but no success.

I have the following code:

procedure TFrm_Aux_POP.IWFileUploadJQFileUploadOptionsUpload(Sender: TObject;
AParams: TStringList);
begin
CDS_CadastroARQUIVO_NOME.AsString := ExtractFileName(WHAT SHOULD I PUT HERE ?);
end;
Lynkin
 
Posts: 26
Joined: 24 Apr 2014 19:53

by Jorge Sousa » 02 May 2014 19:10

Hi

What is in the jQueryDemo_V2?
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by Jorge Sousa » 02 May 2014 22:33

:D

C:\Users\Lynkin\Documents\CGDevTools\IWCGJQComps\JQueryDemoV2\IWCGFrames\CGFileUpload.pas
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by Lynkin » 05 May 2014 17:30

Thanks, but, I know where to find the demo files... but that wasn't helpful for what I want... :(
Lynkin
 
Posts: 26
Joined: 24 Apr 2014 19:53

by Jorge Sousa » 05 May 2014 17:34

Isn't this what you want?

I have a form with 3 fields that will store the FILE NAME, EXTENSION and SIZE of the file. I have this form done on Delphi and now i need to rebuild it using CGDevTools. I'm using the "FileUpload" component to select files but now i need to get those 3 options and store them into my fields. Anyone willing to help me out with this?

editFile_Name (name of the file)
editFile_Ext (extension of the file)
editFile_Size (size of the file)
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by Lynkin » 05 May 2014 17:59

I'll try to explain with more detail:

I have 3 fields in my project:

TIWCGJQEdit1 - this will receive the file name.
TIWCGJQEdit2 - this will receive the file extension.
TIWCGJQEdit3 - this will receive the file size.

I have added the "TIWCGJQFileUpload" component so i could select the file i want from my computer and send to the database.

I haven't specified any "Path" for the file.

To get the name i have tried to use the following event "FileUploadOptionsComplete" by typing:


Delphi Code:

var
fullFileName : String;

begin
fullFileName := WebApplication.UserCacheDir;
TIWCGJQEdit1.Text := ExtractFileName(WebApplication.UserCacheDir);
end;

I'm not even sure if this method is correct, once again, i'm new to programming but i'm stuck at this task since 1 week ago. Any help would be appreciated.
Lynkin
 
Posts: 26
Joined: 24 Apr 2014 19:53

by Jorge Sousa » 05 May 2014 18:50

Look at the source file of CGFileUpload.pas

you can see at design-time that IWCGJQFileUpload.JQFileUploadOptions.OnComplete = TIWCGJQCustomFileUploadComplete

Code: Select all
procedure TIWFileUploadFrame.TIWCGJQCustomFileUploadComplete(Sender: TObject;
  AURLParams: TStringList);
var
  i,c: Integer;
  s: string;
begin
  c:= IWCGJQFileUpload.FileNames.Count;
  if c <= 0 then Exit;
  s:= IntToStr(c) + ' file';
  if c <> 1 then
    s:= s + 's';
  s:= s + ' downloaded:'+sLineBreak;
  for i:= 0 to c-1 do
  begin
    s:= s + IWCGJQFileUpload.FileNames.Names[i] + sLineBreak;
  end;
  IWLabelStatus.Caption:= s;
  IWCGJQDialog.Visible:= True;
end;


Since this component supports multifile upload, you can force single upload, setting

IWCGJQFileUpload.JQFileUploadOptions.Multiple:= False;

Like it's also described in the demo.

In this case you only need to get

FullFileName:= IWCGJQFileUpload.FileNames.ValuesByIndex[0]

that gives you the complete path of the file the user just uploaded,

IWCGJQFileUpload.FileNames.Names[0]

gives you the FileName part only

for gettting the extension use ExtractFileExt

for getting the size, you can use the util function above where you have to pass the FullFileName

please be sure to IWCGJQFileUploadFileNames.Clear, at the end of OnComplete

and thats it....
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58


Return to JQFileUpload

Who is online

Users browsing this forum: No registered users and 4 guests

Contact Us.