On 12 Dec 2018, at 17:26, horrido <horrido.hobbies@gmail.com> 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 <
horrido.hobbies@
> 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