Submitting HTML Forms

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Submitting HTML Forms

horrido
I'm having a lot of difficulty getting file uploading to work using Teapot/Zinc. The documentation is not entirely clear about how it's supposed to work, and the example provided doesn't quite work. I'm referring to section "4.6 Submitting HTML Forms" in "Enterprise Pharo – a Web Perspective."

Here's my setup...

I have a Teapot route like:

GET: '/upload-handler' -> [ :req | self uploadHandler: req ];

where

uploadHandler: req
   ^ '<div>
      <form method="POST" action="upload-handler"  enctype="multipart/form-data">
         <input type="file" name="fileupload">
         <input type="submit" value="Upload!">
      </form>
      </div>'

I have a submission form like:

GET: '/submission' -> [ :req | self submissionPage: req ];
POST: '/submission' -> [ :req | self handleSubmission: req ];

where

submissionPage: req
   ^ '<div>
      <form method="POST">
         <input type="file" name="fileupload" value="">
         <input type="submit" value="Submit">
      </form>
      </div>'

handleSubmission: req
   ZnClient new
      addPart: (ZnMimePart
         fieldName: 'fileupload' fileNamed: 'S1-ABCD012345.st' );
      post.

When I submit the submission form, I get "FileDoesNotExist: File @ /S1-ABCD012345.st".

It doesn't matter what path I use to get to S1-ABCD012345.st. I tried "/Users/richardeng/Documents". I tried "/Documents". I tried "/". I don't know what path it's looking for. The file is there – there's no reason why it can't find it.

I guess I'm just not understanding how this whole thing is supposed to work. Any ideas?

Richard
Reply | Threaded
Open this post in threaded view
|

Re: Submitting HTML Forms

Sven Van Caekenberghe-2
Richard,

You are mixing several aspects. I can only answer for Zinc itself, not Teapot.

First start a local server

  ZnServer startDefaultOn: 1701.

Then go to the example (handler) at http://localhost:1701/form-test-3 and try uploading a text file. If all goes well you will see its contents displayed. Check the code at ZnDefaultServerDelegate>>#formTest3:

To do the same programmatically, client side, do

ZnClient new
  url: 'http://localhost:1701/form-test-3';
  addPart: (ZnMimePart fieldName: 'file' fileNamed: '/tmp/foo.txt');
  post.

In the response HTML that you get back, you will see the contents of your text file.

Of course the field name must match what the handler expects.

HTH,

Sven

> On 12 Dec 2018, at 05:13, Richard Kenneth Eng <[hidden email]> wrote:
>
> I'm having a lot of difficulty getting file uploading to work using Teapot/Zinc. The documentation is not entirely clear about how it's supposed to work, and the example provided doesn't quite work. I'm referring to section "4.6 Submitting HTML Forms" in "Enterprise Pharo – a Web Perspective."
>
> Here's my setup...
>
> I have a Teapot route like:
>
> GET: '/upload-handler' -> [ :req | self uploadHandler: req ];
>
> where
>
> uploadHandler: req
>    ^ '<div>
>       <form method="POST" action="upload-handler"  enctype="multipart/form-data">
>          <input type="file" name="fileupload">
>          <input type="submit" value="Upload!">
>       </form>
>       </div>'
>
> I have a submission form like:
>
> GET: '/submission' -> [ :req | self submissionPage: req ];
> POST: '/submission' -> [ :req | self handleSubmission: req ];
>
> where
>
> submissionPage: req
>    ^ '<div>
>       <form method="POST">
>          <input type="file" name="fileupload" value="">
>          <input type="submit" value="Submit">
>       </form>
>       </div>'
>
> handleSubmission: req
>    ZnClient new
>       url: 'http://174.117.171.194/upload-handler';
>       addPart: (ZnMimePart
>          fieldName: 'fileupload' fileNamed: 'S1-ABCD012345.st' );
>       post.
>
> When I submit the submission form, I get "FileDoesNotExist: File @ /S1-ABCD012345.st".
>
> It doesn't matter what path I use to get to S1-ABCD012345.st. I tried "/Users/richardeng/Documents". I tried "/Documents". I tried "/". I don't know what path it's looking for. The file is there – there's no reason why it can't find it.
>
> I guess I'm just not understanding how this whole thing is supposed to work. Any ideas?
>
> Richard


Reply | Threaded
Open this post in threaded view
|

Re: Submitting HTML Forms

horrido
Okay, I managed to hack together a solution from the example. It's not pretty
but it seems to work. I needed to remain within the Teapot framework.

However, I have a question regarding the ZnEntityTooLarge exception. How can
I capture it and resume execution? The exception seems to occur before my
POST handler is called.



Sven Van Caekenberghe-2 wrote

> Richard,
>
> You are mixing several aspects. I can only answer for Zinc itself, not
> Teapot.
>
> First start a local server
>
>   ZnServer startDefaultOn: 1701.
>
> Then go to the example (handler) at http://localhost:1701/form-test-3 and
> try uploading a text file. If all goes well you will see its contents
> displayed. Check the code at ZnDefaultServerDelegate>>#formTest3:
>
> To do the same programmatically, client side, do
>
> ZnClient new
>   url: 'http://localhost:1701/form-test-3';
>   addPart: (ZnMimePart fieldName: 'file' fileNamed: '/tmp/foo.txt');
>   post.
>
> In the response HTML that you get back, you will see the contents of your
> text file.
>
> Of course the field name must match what the handler expects.
>
> HTH,
>
> Sven
>
>> On 12 Dec 2018, at 05:13, Richard Kenneth Eng &lt;

> horrido.hobbies@

> &gt; wrote:
>>
>> I'm having a lot of difficulty getting file uploading to work using
>> Teapot/Zinc. The documentation is not entirely clear about how it's
>> supposed to work, and the example provided doesn't quite work. I'm
>> referring to section "4.6 Submitting HTML Forms" in "Enterprise Pharo – a
>> Web Perspective."
>>
>> Here's my setup...
>>
>> I have a Teapot route like:
>>
>> GET: '/upload-handler' -> [ :req | self uploadHandler: req ];
>>
>> where
>>
>> uploadHandler: req
>>    ^ '
> <div>
>>      
> <form method="POST" action="upload-handler"
> enctype="multipart/form-data">
>>          
> <input type="file" name="fileupload">
>>          
> <input type="submit" value="Upload!">
>>      
> </form>
>>      
> </div>
> '
>>
>> I have a submission form like:
>>
>> GET: '/submission' -> [ :req | self submissionPage: req ];
>> POST: '/submission' -> [ :req | self handleSubmission: req ];
>>
>> where
>>
>> submissionPage: req
>>    ^ '
> <div>
>>      
> <form method="POST">
>>          
> <input type="file" name="fileupload" value="">
>>          
> <input type="submit" value="Submit">
>>      
> </form>
>>      
> </div>
> '
>>
>> handleSubmission: req
>>    ZnClient new
>>       url: 'http://174.117.171.194/upload-handler';
>>       addPart: (ZnMimePart
>>          fieldName: 'fileupload' fileNamed: 'S1-ABCD012345.st' );
>>       post.
>>
>> When I submit the submission form, I get "FileDoesNotExist: File @
>> /S1-ABCD012345.st".
>>
>> It doesn't matter what path I use to get to S1-ABCD012345.st. I tried
>> "/Users/richardeng/Documents". I tried "/Documents". I tried "/". I don't
>> know what path it's looking for. The file is there – there's no reason
>> why it can't find it.
>>
>> I guess I'm just not understanding how this whole thing is supposed to
>> work. Any ideas?
>>
>> Richard





--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: Submitting HTML Forms

Sven Van Caekenberghe-2


> On 12 Dec 2018, at 17:26, horrido <[hidden email]> wrote:
>
> Okay, I managed to hack together a solution from the example. It's not pretty
> but it seems to work. I needed to remain within the Teapot framework.
>
> However, I have a question regarding the ZnEntityTooLarge exception. How can
> I capture it and resume execution? The exception seems to occur before my
> POST handler is called.

The default is 16Mb. Nowadays you can set it using #maximumEntitySize: on ZnServer (and on ZnClient). There is also a dynamic/process-local variable ZnMaximumEntitySize.

> Sven Van Caekenberghe-2 wrote
>> Richard,
>>
>> You are mixing several aspects. I can only answer for Zinc itself, not
>> Teapot.
>>
>> First start a local server
>>
>>  ZnServer startDefaultOn: 1701.
>>
>> Then go to the example (handler) at http://localhost:1701/form-test-3 and
>> try uploading a text file. If all goes well you will see its contents
>> displayed. Check the code at ZnDefaultServerDelegate>>#formTest3:
>>
>> To do the same programmatically, client side, do
>>
>> ZnClient new
>>  url: 'http://localhost:1701/form-test-3';
>>  addPart: (ZnMimePart fieldName: 'file' fileNamed: '/tmp/foo.txt');
>>  post.
>>
>> In the response HTML that you get back, you will see the contents of your
>> text file.
>>
>> Of course the field name must match what the handler expects.
>>
>> HTH,
>>
>> Sven
>>
>>> On 12 Dec 2018, at 05:13, Richard Kenneth Eng &lt;
>
>> horrido.hobbies@
>
>> &gt; wrote:
>>>
>>> I'm having a lot of difficulty getting file uploading to work using
>>> Teapot/Zinc. The documentation is not entirely clear about how it's
>>> supposed to work, and the example provided doesn't quite work. I'm
>>> referring to section "4.6 Submitting HTML Forms" in "Enterprise Pharo – a
>>> Web Perspective."
>>>
>>> Here's my setup...
>>>
>>> I have a Teapot route like:
>>>
>>> GET: '/upload-handler' -> [ :req | self uploadHandler: req ];
>>>
>>> where
>>>
>>> uploadHandler: req
>>>   ^ '
>> <div>
>>>
>> <form method="POST" action="upload-handler"
>> enctype="multipart/form-data">
>>>
>> <input type="file" name="fileupload">
>>>
>> <input type="submit" value="Upload!">
>>>
>> </form>
>>>
>> </div>
>> '
>>>
>>> I have a submission form like:
>>>
>>> GET: '/submission' -> [ :req | self submissionPage: req ];
>>> POST: '/submission' -> [ :req | self handleSubmission: req ];
>>>
>>> where
>>>
>>> submissionPage: req
>>>   ^ '
>> <div>
>>>
>> <form method="POST">
>>>
>> <input type="file" name="fileupload" value="">
>>>
>> <input type="submit" value="Submit">
>>>
>> </form>
>>>
>> </div>
>> '
>>>
>>> handleSubmission: req
>>>   ZnClient new
>>>      url: 'http://174.117.171.194/upload-handler';
>>>      addPart: (ZnMimePart
>>>         fieldName: 'fileupload' fileNamed: 'S1-ABCD012345.st' );
>>>      post.
>>>
>>> When I submit the submission form, I get "FileDoesNotExist: File @
>>> /S1-ABCD012345.st".
>>>
>>> It doesn't matter what path I use to get to S1-ABCD012345.st. I tried
>>> "/Users/richardeng/Documents". I tried "/Documents". I tried "/". I don't
>>> know what path it's looking for. The file is there – there's no reason
>>> why it can't find it.
>>>
>>> I guess I'm just not understanding how this whole thing is supposed to
>>> work. Any ideas?
>>>
>>> Richard
>
>
>
>
>
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html


Reply | Threaded
Open this post in threaded view
|

Re: Submitting HTML Forms

Ben Coman
In reply to this post by horrido


On Thu, 13 Dec 2018 at 00:27, horrido <[hidden email]> wrote:
Okay, I managed to hack together a solution from the example. It's not pretty
but it seems to work. I needed to remain within the Teapot framework.

However, I have a question regarding the ZnEntityTooLarge exception. How can
I capture it and resume execution? The exception seems to occur before my
POST handler is called.

I'm not familiar with that exception, but in general you can wrap code like this...

myMethod
    [  do stuff ] on: ZnEntityTooLarge do: [ :ex | fix stuff. ex resume ]

cheers -ben

P.S. The exception should open a debugger where the exception was signaled,
and that should be all you need to identify what code you need to wrap,
but if for some exotic reason you really want to know where the ZnEntityTooLarge is created,
add ZnEntityTooLarge>>initialize that does "self haltOnce"
Reply | Threaded
Open this post in threaded view
|

Re: Submitting HTML Forms

Sven Van Caekenberghe-2


> On 12 Dec 2018, at 20:02, Ben Coman <[hidden email]> wrote:
>
>
>
> On Thu, 13 Dec 2018 at 00:27, horrido <[hidden email]> wrote:
> Okay, I managed to hack together a solution from the example. It's not pretty
> but it seems to work. I needed to remain within the Teapot framework.
>
> However, I have a question regarding the ZnEntityTooLarge exception. How can
> I capture it and resume execution? The exception seems to occur before my
> POST handler is called.
>
> I'm not familiar with that exception, but in general you can wrap code like this...
>
> myMethod
>     [  do stuff ] on: ZnEntityTooLarge do: [ :ex | fix stuff. ex resume ]

No! Sorry this is plain wrong. Read the comment and what I replied.

> cheers -ben
>
> P.S. The exception should open a debugger where the exception was signaled,
> and that should be all you need to identify what code you need to wrap,
> but if for some exotic reason you really want to know where the ZnEntityTooLarge is created,
> add ZnEntityTooLarge>>initialize that does "self haltOnce"