Posts: 64
Threads: 9
Joined: Jun 2019
Reputation:
0
Location: here
intraweb 15.1.5
I am looking for a very simple example of uploading one file (png,jpg,gif,bmp). Select file, upload, on upload success, on upload failure. What I have found is too broad and difficult to understand.
In particular I need to know how to assign an individual temporary directory for uploaded files for each session so that users should not overwrite other users uploaded files.
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
IW doesnt save the files using the name of the original files so duplicate file names are ok. IW saves them as temp files and then you as the user choose to save those files with a name you specify if you want to keep the uploads.
The demos should show this clearly.
Posts: 64
Threads: 9
Joined: Jun 2019
Reputation:
0
Location: here
(12-16-2019, 02:49 PM)kudzu Wrote: IW doesnt save the files using the name of the original files so duplicate file names are ok. IW saves them as temp files and then you as the user choose to save those files with a name you specify if you want to keep the uploads.
The demos should show this clearly. The demos do not show this clearly. At least I need to know two methods - to choose the file at user's computer and to send the file to server, maybe then to move it from temporary directory to a different one.
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
Without looking, Im sure the demos MUST save the files as it is the only way. Just change the parameter to whatever you want for the name.
http://docs.atozed.com/docs.dll/controls...oader.html
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
12-16-2019, 10:32 PM
(This post was last modified: 12-16-2019, 11:09 PM by kudzu.)
https://github.com/Atozed/IntraWeb/blob/.../Unit7.pas
Line 118:
// save in the same application directory, with the same name of the original file. Overwrite if it already exists.
IWFileUploader5.SaveToFile(FileName, CurDir + FileName, True);
The demos DO show exactly as you ask. Just modify the parameter to save wherever you want to save it.
Posts: 64
Threads: 9
Joined: Jun 2019
Reputation:
0
Location: here
None of the two web addresses tell anything about methods IWFileUploader1.SelectFile IWFileUploader1.StartUpload
which must be used first, as if it was obvious.
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
Have you run and played with the demo I pointed out? Its fully functional.
Posts: 288
Threads: 0
Joined: Mar 2018
Reputation:
29
Location: Franca-São Paulo-Brasil
Hi, IWFileUpload has propertie: ButtonVisible, it is True?. When you click in his button, they show you to select file, when you selected the file, iwfileupload upload your file automatic. After upload, iwfileupload fire AsyncUploadCompleted. You can create your folder, save your file, etc there.
Code: procedure TIWForm.IWFileUploader1AsyncUploadCompleted(Sender: TObject;
var DestPath, FileName: string; var SaveFile, Overwrite: Boolean);
var
CurDir: string;
begin
// get the app path
CurDir := TIWAppInfo.GetAppPath;
// save in the same application directory, with the same name of the original file. Overwrite if it already exists.
IWFileUploader.SaveToFile(FileName, CurDir + FileName, True);
// Inform IWFileUploader that we are taking care of file saving ourselves
SaveFile := False;
end;
Posts: 2,256
Threads: 195
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
12-17-2019, 09:47 PM
(This post was last modified: 12-17-2019, 10:16 PM by Alexandre Machado.)
(12-17-2019, 01:59 AM)MrSpock Wrote: None of the two web addresses tell anything about methods IWFileUploader1.SelectFile IWFileUploader1.StartUpload
which must be used first, as if it was obvious.
You don't need to select the file and start the upload yourself. These methods have nothing to do with the way the files are saved in the server.
You have 2 options to deal with it:
Option 1) Implement the event OnAsyncUploadCompleted. Please check out this example and read the comments:
Code: procedure TIWForm1.IWFileUploader1AsyncUploadCompleted(
Sender: TObject; var DestPath, FileName: string; var SaveFile,
Overwrite: Boolean);
begin
// save in the user cache directory with the same name of the original file. Overwrite if it already exists.
// Each user directory is exclusive. Files won't be overwritten by other users
IWFileUploader1.SaveToFile(WebApplication.UserCacheDir, WebApplication.UserCacheDir + FileName, True);
// Inform IWFileUploader that we are taking care of file saving ourselves
SaveFile := False;
end;
Option 2) You can achieve the same thing (without coding the event), if you set IWFileUploader.AutoSavePath property when you create the form (you can only do this at runtime, not at design time):
Code: procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
IWFileUploader1.AutoSavePath := WebApplication.UserCacheDir;
end;
In the above case, you don't need to do anything else (no need for OnAsyncUploadCompleted event)
Just a note: UserCacheDir and everything it contains is deleted by IW application when it terminates. So, after saving the file there you might want to move it to somewhere else (if want to keep it, anyway).
Posts: 64
Threads: 9
Joined: Jun 2019
Reputation:
0
Location: here
12-21-2019, 08:17 PM
(This post was last modified: 12-21-2019, 09:58 PM by MrSpock.)
in procedure TIWForm1.IWFileUploader1AsyncUploadCompleted
I change in code label.caption or label.visible but that cannot be seen, form components are not refreshed.
What is funny is that components are refreshed in IWFileUploader1AsyncUploadSuccess
|