Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: OnSubmit evento of TIWFileUploader


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 18 - Last Post: Jun 22, 2017 9:55 AM Last Post By: Júlio César Men...
Júlio César Men...

Posts: 14
Registered: 3/20/09
OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 5:44 AM
Hello,

We have a problem with the TIWFileUploader component. We are trying to upload a PDF file to an IIS server. In the OnAsyncUploadCompleted event, the file is renamed and copied to a our specific system directory (this part works flawlessly!).

In the OnSubmit event, we are trying to draw the file information in a TIWDBGrid component, but it does not work. The Intraweb is not performing the "submit".

We have already tried to use the OnAsyncUploadSuccess event to do this and even running the code below, but to no avail.

objectGrid.Update;

or
objectGrid.Refresh;
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 10:26 AM   in response to: Júlio César Men... in response to: Júlio César Men...
It sounds like you are mixing synchronous and asynchronous events, which will not work. The upload is asynchronous so you will have to do everything there. What are you trying to accomplish, exactly?
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 11:02 AM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
It sounds like you are mixing synchronous and asynchronous events, which will not work. The upload is asynchronous so you will have to do everything there. What are you trying to accomplish, exactly?

The page attempts to upload a PDF file to the configured cache directory. This opens the file in stream format and writes it to a table in the database.

After this procedure, the file name and its size are displayed in an IWDBGrid component, through a database query, in the same table that received the stream in the step above.

Via localhost, everything works. The page performs a submit, is reloaded and the information appears. But when I try to run through the public domain, the submit can not be executed and the page remains "static".
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 12:03 PM   in response to: Júlio César Men... in response to: Júlio César Men...
Does everything fail? Even the upload itself?

Possible problems:
1. MIME Type for the PDF is not installed on the server.
2. Access restrictions imposed by the server. Your application may be being blocked from accessing the folder referenced by your code.
3. Server environment does not match development environment. Perhaps you have hard-coded a path to access files that does not exist on the server.

I would wrap the code in a try...except block and then write errors to a file. You have to let the server tell you what is happening. If your code is inside a try...finally block, you may not be letting the actual error surface.
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 12:19 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
Does everything fail? Even the upload itself?

Possible problems:
1. MIME Type for the PDF is not installed on the server.
2. Access restrictions imposed by the server. Your application may be being blocked from accessing the folder referenced by your code.
3. Server environment does not match development environment. Perhaps you have hard-coded a path to access files that does not exist on the server.

I would wrap the code in a try...except block and then write errors to a file. You have to let the server tell you what is happening. If your code is inside a try...finally block, you may not be letting the actual error surface.

Dear Daniel,

1. The MIM type is configured on IIS server (7) like ".pdf -> application/pdf"
2. The directory used is c:\temp\ and It has full access / write / read permission for all common IIS users, Administrators, and Owner
3. This path configuration is for the cache directory ou is another specific path?
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 12:04 PM   in response to: Júlio César Men... in response to: Júlio César Men...
Júlio César Mendonça Ferreira wrote:
Daniel Fields wrote:
It sounds like you are mixing synchronous and asynchronous events, which will not work. The upload is asynchronous so you will have to do everything there. What are you trying to accomplish, exactly?

The page attempts to upload a PDF file to the configured cache directory. This opens the file in stream format and writes it to a table in the database.

After this procedure, the file name and its size are displayed in an IWDBGrid component, through a database query, in the same table that received the stream in the step above.

Via localhost, everything works. The page performs a submit, is reloaded and the information appears. But when I try to run through the public domain, the submit can not be executed and the page remains "static".

I've seen a similar kind of thing with something else I was trying to render. That may have been an image, it's been a while and I've forgot the details.

What I do remember is that the problem was in the filespec. The file was being referenced locally (off a windows drive), which works just fine on the local machine. Make sure the reference to the file you're rendering is a good URI pointing to the server. That should be in a public directory on the server. It sounds like the file will be session specific, so you'll want to create a public session specific directory.

You can test that theory by placing it in wwwroot initially. You may also need to register the MIME type (not sure what your grid is doing). If placing it in the wwwroot (and assuring that you use a URI that points to the server) fixes the problem we can talk about creating session specific directories.

This may not be your problem, but the symptoms sure sound familiar. It may be worth checking if you can use debug to get a look at the explicit filespec on the pdf.

Dan
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 12:22 PM   in response to: Dan Barclay in response to: Dan Barclay
Dan Barclay wrote:
Júlio César Mendonça Ferreira wrote:
Daniel Fields wrote:
It sounds like you are mixing synchronous and asynchronous events, which will not work. The upload is asynchronous so you will have to do everything there. What are you trying to accomplish, exactly?

The page attempts to upload a PDF file to the configured cache directory. This opens the file in stream format and writes it to a table in the database.

After this procedure, the file name and its size are displayed in an IWDBGrid component, through a database query, in the same table that received the stream in the step above.

Via localhost, everything works. The page performs a submit, is reloaded and the information appears. But when I try to run through the public domain, the submit can not be executed and the page remains "static".

I've seen a similar kind of thing with something else I was trying to render. That may have been an image, it's been a while and I've forgot the details.

What I do remember is that the problem was in the filespec. The file was being referenced locally (off a windows drive), which works just fine on the local machine. Make sure the reference to the file you're rendering is a good URI pointing to the server. That should be in a public directory on the server. It sounds like the file will be session specific, so you'll want to create a public session specific directory.

You can test that theory by placing it in wwwroot initially. You may also need to register the MIME type (not sure what your grid is doing). If placing it in the wwwroot (and assuring that you use a URI that points to the server) fixes the problem we can talk about creating session specific directories.

This may not be your problem, but the symptoms sure sound familiar. It may be worth checking if you can use debug to get a look at the explicit filespec on the pdf.

Dan

Dan,

It is a public directory in the same level of wwwroot

The following is the physical structure of the directories:

- c:
- - wwwroot
- - - portal (web system)
- - temp
- - - portal
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 12:44 PM   in response to: Júlio César Men... in response to: Júlio César Men...
Júlio César Mendonça Ferreira wrote:

It is a public directory in the same level of wwwroot

The following is the physical structure of the directories:

- c:
- - wwwroot
- - - portal (web system)
- - temp
- - - portal

In order for it to be visible through the web server put it in (or under) wwwroot.

Also, make sure the spec for the PDF is relative to the app and does not contain a drivespec. If you use a full filespec it would create the symptom you are describing. That is, if the client is running on the same machine as the server and receives a "c:\xxxxxyyy\temp\portal\myfile.pdf" then the client knows where to get the file, but goes around the server. You could put it in C:\MyFiles and it would still find it.

As a test to see if this is happening, on the "remote" machine you can temporarily create a directory structure like you have shown above and manually place the pdf in the folder. If that causes it to render then we are chasing the right rabbit.

The file needs to be requested from the server, not the local file system.

Dan
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 12:30 PM   in response to: Júlio César Men... in response to: Júlio César Men...
How are you rendering the PDF?
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 12:45 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
How are you rendering the PDF?

Daniel,

It is not rendered. It is only sent to the server, where it is saved in the database. The routine only allows you to upload and download the file, not your view.
The grid displays the name of the file that was uploaded and its size in megabytes.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 1:01 PM   in response to: Júlio César Men... in response to: Júlio César Men...
OK. Does any part of the process work on the server? Does the upload itself fail? Does the database code fail?
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 1:11 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
OK. Does any part of the process work on the server? Does the upload itself fail? Does the database code fail?

Uploading works well! I can see the file in the cache directory on the server.
The process of renaming the file also works.
The process of loading this file by stream and saving to the database also works.
After that, the page can't execute the submit (apparently nothing happens) and the OnSubmit event of IWFileUploader is set to query the table and bring the "name" and "size" information of the saved PDF.

Stop there! Nothing else happens.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 1:30 PM   in response to: Júlio César Men... in response to: Júlio César Men...
Where is the OnSubmit event? I have always used the FIleUploader.OnAsyncUploadCompleted to do everything, all processing of the upload goes there. Where are you seeing an OnSubmit event?
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 3:07 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
Where is the OnSubmit event? I have always used the FIleUploader.OnAsyncUploadCompleted to do everything, all processing of the upload goes there. Where are you seeing an OnSubmit event?

In this method, the PDF stream was written to the database. But this process has been moved to AsyncComppleted. However, I still can not update the grid with the information.

Currently, this is the problem: The upload is done. The recording in the table is done. The screen update to display the information on the grid, no.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 3:37 PM   in response to: Júlio César Men... in response to: Júlio César Men...
If you have CGDevTools, you can call RenderRegionAsync(MyGridRegion), which would force a redraw. I do not use the standard grids, so I'm not sure if they have an async refresh method.

You might try showing a message dialog at the end, which might trigger the grid to refresh.
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 3:56 PM   in response to: Júlio César Men... in response to: Júlio César Men...
Júlio César Mendonça Ferreira wrote:
Hello,

We have a problem with the TIWFileUploader component. We are trying to upload a PDF file to an IIS server. In the OnAsyncUploadCompleted event, the file is renamed and copied to a our specific system directory (this part works flawlessly!).

In the OnSubmit event, we are trying to draw the file information in a TIWDBGrid component, but it does not work. The Intraweb is not performing the "submit".

We have already tried to use the OnAsyncUploadSuccess event to do this and even running the code below, but to no avail.

The best way to force a complete refresh is posting a submit from the OnAsyncUploadCompleted. I'll need a couple of hours to find the exact code used to do that, though :-)
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2017 12:28 PM   in response to: Alexandre Machado in response to: Alexandre Machado
Alexandre Machado wrote:
Júlio César Mendonça Ferreira wrote:
Hello,

We have a problem with the TIWFileUploader component. We are trying to upload a PDF file to an IIS server. In the OnAsyncUploadCompleted event, the file is renamed and copied to a our specific system directory (this part works flawlessly!).

In the OnSubmit event, we are trying to draw the file information in a TIWDBGrid component, but it does not work. The Intraweb is not performing the "submit".

We have already tried to use the OnAsyncUploadSuccess event to do this and even running the code below, but to no avail.

The best way to force a complete refresh is posting a submit from the OnAsyncUploadCompleted. I'll need a couple of hours to find the exact code used to do that, though :-)

Alexandre,

We are still very much in need of this solution. Could this example you mentioned be made available? We have the Intraweb license, but I could not find anything explaining this in the component manual, seen at http://docs.atozed.com/docs.dll/index.html

Thank you for your attention and I await your arrival.

PS: I am Brazilian and we can exchange messages in Portuguese, if it is more convenient for you.
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 19, 2017 11:44 PM   in response to: Júlio César Men... in response to: Júlio César Men...
Hi Julio,

please use this code and see if it solves your issue:

procedure TIWForm51.IWFileUploader1AsyncUploadSuccess(Sender: TObject; EventParams: TStringList);
var
  js: string;
begin
  // this will force the page reload
  js := 'location.reload(true);';
  WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(js);
end;
 


This will submit the form, causing a full refresh, after the successful upload.
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: OnSubmit evento of TIWFileUploader  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 22, 2017 9:55 AM   in response to: Alexandre Machado in response to: Alexandre Machado
Alexandre Machado wrote:
Hi Julio,

please use this code and see if it solves your issue:

procedure TIWForm51.IWFileUploader1AsyncUploadSuccess(Sender: TObject; EventParams: TStringList);
var
  js: string;
begin
  // this will force the page reload
  js := 'location.reload(true);';
  WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(js);
end;
 


This will submit the form, causing a full refresh, after the successful upload.

Alexandre,

Your solution worked flawlessly. But I found another problem a little stranger. The grid has a button to delete the attachment that was recorded via upload.

The button already performs a submit and removes the "record" successfully. The problem is that after deleting, I can no longer do a new upload. Just leave the page and enter again.

I have no idea what it can be. Any tips?
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02