Transfer a file to httpserver via POST command from curl

Peter J. Holzer hjp-python at hjp.at
Mon Dec 23 10:43:18 EST 2019


On 2019-12-23 04:24:22 +1100, Chris Angelico wrote:
> On Mon, Dec 23, 2019 at 4:20 AM <musbur at posteo.org> wrote:
> > On Wed, 18 Dec 2019 04:52:33 +1100
> > Chris Angelico <rosuav at gmail.com> wrote:
> >
> > > On Wed, Dec 18, 2019 at 4:45 AM <musbur at posteo.org> wrote:
> > > > BTW, the canonical way to upload files via http is PUT, not POST.
> > > > You might want to look into that, but here it is off-topic.
> > >
> > > Citation needed.
> >
> > https://tools.ietf.org/html/rfc2616#page-55
> 
> Yes, that's the definition of PUT - but what does that mean in terms
> of file uploads? POST is also valid. Look at its example usages.

ACK. Also the first sentence reads:

| The PUT method requests that the enclosed entity be stored under the
| supplied Request-URI.

I understand this to mean that when I send a 

    PUT https://example.com/foo/bar

request and receive a 201 or 204 response, a subsequent

    GET https://example.com/foo/bar

will return the body I sent in the PUT request.

This is fine if the client can determine the URI of the response.

Quite often this not what you want. You want the client to supply the
data but let the server determine what to do with it. For example, the
server might just number the uploaded files (or use a timestamp or a
hash). Or the uploaded file may not be available under any URL at all,
but is used to modify other resources and then discarded.

In these cases PUT is inappropriate and POST is appropriate.

And sometimes the uploaded file is only part of the data (think of HTML
forms with a file input field). Then POST is also the correct choice.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20191223/d2dcc234/attachment.sig>


More information about the Python-list mailing list