Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IWFileUploader using
#1
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.
Reply
#2
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.
Reply
#3
(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.
Reply
#4
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
Reply
#5
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.
Reply
#6
None of the two web addresses tell anything about methods IWFileUploader1.SelectFile IWFileUploader1.StartUpload
which must be used first, as if it was obvious.
Reply
#7
Have you run and played with the demo I pointed out? Its fully functional.
Reply
#8
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;
Reply
#9
(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).
Reply
#10
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
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)