Greetings,
Of course we all know how to do implement that in our applications. But just in case you do not (just as I did not), here is the HOWTO.
It all starts with a special field in your HTML form, a file field.
This will provide you with a textfield, a browse button (to browse your filesystem for the file) and a submit button. That''s what I call value for money.
I process the submit in a simple (almost too simple) DPML program. This is the main instruction :
That''s it. I first determine where I want the file and put that in var:uri and then the above copy will do the uploading.
Comments :
- I still work in NetKernel 3.3. I presume it is even easier in NetKernel 4 to do this.
- I''ve tested this with files up to +/- 5Mb. So do not blame me if your >2Gb upload fails. Caveat Emptor.
- Apparantly a form with a file-type field can NOT be submitted with vanilla Ajax. The framework I use (ExtJS) has a rather complicated structure around this (and requires the response to be a JSON response with Content-Type text/html ... really fun to get that right). Behind the screens it still does a ''normal'' form submit. You might want to check up on the right procedures for your framework before stating that you can do this in ''no time'' ;-). Or not use a javascript framework at all of course.
Enjoy,
Tom
Of course we all know how to do implement that in our applications. But just in case you do not (just as I did not), here is the HOWTO.
It all starts with a special field in your HTML form, a file field.
|
<html>
<body> <formaction="http://networkconfig/upload" enctype="multipart/form-data" method="post"> <inputname="uploadfile" size="60" type="file" value="" /> <inputtype="submit" /> </form> </body> </html> |
This will provide you with a textfield, a browse button (to browse your filesystem for the file) and a submit button. That''s what I call value for money.
I process the submit in a simple (almost too simple) DPML program. This is the main instruction :
|
<instr>
<type>copy</type> <operand>this:param:uploadfile</operand> <target>curi:var:uri</target> </instr> |
That''s it. I first determine where I want the file and put that in var:uri and then the above copy will do the uploading.
Comments :
- I still work in NetKernel 3.3. I presume it is even easier in NetKernel 4 to do this.
- I''ve tested this with files up to +/- 5Mb. So do not blame me if your >2Gb upload fails. Caveat Emptor.
- Apparantly a form with a file-type field can NOT be submitted with vanilla Ajax. The framework I use (ExtJS) has a rather complicated structure around this (and requires the response to be a JSON response with Content-Type text/html ... really fun to get that right). Behind the screens it still does a ''normal'' form submit. You might want to check up on the right procedures for your framework before stating that you can do this in ''no time'' ;-). Or not use a javascript framework at all of course.
Enjoy,
Tom