Jump to content

TUniFileUpload: Is it possible to execute without the dialog?


Guest tendon

Recommended Posts

Guest tendon

IIUC, UniFileUpload.Execute will display a dialog whereby the user can choose a file to upload.

 

Is it possible to execute the upload without going through that dialog?

 

If not, then can you change the implementation accordingly? Maybe provide an optional param to Execute which represents the file to upload. If it is provided, then just upload; if it is not provided, then show the dialog.

 

Rationale: After getting the DnD to work (see other thread), I'd like to upload the dropped file. I was thinking of using UniFileUpload, but it doesn't work (unless I miss something; but then please advise).

 

If UniFileUpload cannot be used, then I'd have to implement the uploading code directly; but that feels awkward, especially knowing that the necessary functionality is already there in the UniFileUpload component.

Link to comment
Share on other sites

If UniFileUpload cannot be used, then I'd have to implement the uploading code directly;

 

Is there a size limit for params in ajaxRequest?

 

If not, you could use ajaxRequest to send the (already) base64-encoded data to the server. Then, on Server, you must decode the data to a binary file.

Link to comment
Share on other sites

Guest tendon

Is there a size limit for params in ajaxRequest?

 

If not, you could use ajaxRequest to send the (already) base64-encoded data to the server. Then, on Server, you must decode the data to a binary file.

 

Sending the file over an xhr should not have limitations, AFAIK, as it would be chunked and streamed.... See https://developer.mozilla.org/en/XMLHttpRequest#sendAsBinary()

 

(And then we have Browser compatibility to deal with too)

 

However the whole point of my question was to avoid writing such code, because evidently it is already there, hiding somewhere in the TUniFileUpload component, and I guess the grunt work is actually done by ExtJS. Why reinvent the wheel when it is already there?

 

----

 

Update. Maybe it UniFileUpload works via this...

 

http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.BasicForm-cfg-fileUpload

 

... then it is not Ajax at all, but just form posting.

Link to comment
Share on other sites

(Uni)FileUpload uses something like:

 

<form method="post" enctype="multipart/form-data">
 <input name="Datei" type="file">
</form>

 

And modern browsers don't let you change anything (like the "value" attribute) of <input type="file">. The browser lets the user choose a file and only just this will be uploaded for security reasons.

 

Since the Files you got are already been base64-encoded, you could easy use something like:

 

ajaxRequest(MyForm.MyComponent, 'SendFile', ['FileContent='+evt.target.result]);
//(where evt.target.result is the base64-encoded-file you got, see other thread)

 

in Delphi you need then something like:

 

procedure TMyForm.MyComponentAjaxEvent(Sender: TComponent; EventName: string; Params: TStrings);
begin
 if EventName='SendFile' then begin
   //Params.Values['FileContent']; contains the base64-encoded data
   //it should be no problem to decode it here in delphi on server
   //...
 end;
end;

Link to comment
Share on other sites

Guest tendon

For obvious reasons file upload dialog can not be omitted.

 

File upload is a native browser functionality. For security reasons a web site can not upload a file from users' disk without asking them first. Otherwise everyone could grab files with sensitive information.

 

Farshad: you're missing the point. I'm not trying to bypass the user's selecting a file. In fact, as I mentioned, the user has explicitly selected the file through a drag and drop operation.

 

There are two distinct phases here. (1) Allowing the user to indicate what file is to be uploaded; and (2) actually sending that file to the server. The problem with TUniFileUpload is that it makes those two steps tightly integrated. I am interested in how to make step (2).

 

The file upload dialog can very well be omitted. A browser does not need to present a file selection dialog. Often you have a simple text edit, where the user types in the path name of the file to upload, and then clicks on the submit button to send it.

 

So my question to you is this: If I want that kind of interface (i.e. text edit where you type the pathname of the file), and then you want to upload the specified file to the server, how do you suggest that you do that with TUniFileUpload, or with other UniGui components. Or is this an intrinsic limitation that UniGui cannot handle, and I have to resort to coding in Ajax/Javascript all the way? If so, what's the point of using UniGui?

Link to comment
Share on other sites

Guest tendon

(Uni)FileUpload uses something like:

 

<form method="post" enctype="multipart/form-data">
 <input name="Datei" type="file">
</form>

 

And modern browsers don't let you change anything (like the "value" attribute) of <input type="file">. The browser lets the user choose a file and only just this will be uploaded for security reasons.

 

Since the Files you got are already been base64-encoded, you could easy use something like:

 

ajaxRequest(MyForm.MyComponent, 'SendFile', ['FileContent='+evt.target.result]);
//(where evt.target.result is the base64-encoded-file you got, see other thread)

 

in Delphi you need then something like:

 

procedure TMyForm.MyComponentAjaxEvent(Sender: TComponent; EventName: string; Params: TStrings);
begin
 if EventName='SendFile' then begin
   //Params.Values['FileContent']; contains the base64-encoded data
   //it should be no problem to decode it here in delphi on server
   //...
 end;
end;

 

 

That's what I had in mind, but I was missing the AjaxEvent on the UniGui side. Thanks for pointing it out.

 

I'll give your solution a try.

Link to comment
Share on other sites

  • Administrators

The file upload dialog can very well be omitted. A browser does not need to present a file selection dialog. Often you have a simple text edit, where the user types in the path name of the file to upload, and then clicks on the submit button to send it.

 

I'm not aware of such technology, which allows sending files without displaying a dialog screen first. Can you point us to a page that implements this feature?

Link to comment
Share on other sites

I'm not aware of such technology, which allows sending files without displaying a dialog screen first. Can you point us to a page that implements this feature?

 

 

Hi,

 

With the new dropbox UI you can upload a file just with drag and drop.

 

Liriano

Link to comment
Share on other sites

With the new dropbox UI you can upload a file just with drag and drop.

 

That is using HTML5 and works with UniGui too (in Firefox, Chrome and maybe other).

 

With this Code you can drag'n'drop files from Windows Explorer to the Upload-division in your website. The (picture-)file will be displayed below; everything on Clientside:

 

Link

 

Adding this code allows you to upload the files to server:

 

Link

 

But my question to Farshad: Is there a size limit for params in ajaxRequest?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...