Help composing an http:request with POST

Thursday, 21 May 2020 · 2 messages
BD
Bridger Dyson-Smith21 May 2020 01:38 #
Hi all - I'm trying to use BaseX to POST an image to a digital asset management system (i.e. I'm not using RESTXQ, etc, just using BaseX to compose and send the request). The request:
http:send-request(
<http:request method='POST' username='{$user}' password='{$pass}'
    auth-method='Basic' send-authorization='true'>
  <http:multipart media-type='multipart/form-data'>
      <http:body media-type='image/tiff'/>
  </http:multipart>
</http:request>,
'
http://localhost:8080/fedora/objects/tdh:2/datastreams/OBJ?versionable=true?dsLocation=/path/to/my/image.tif
',
file:read-binary('/path/to/my/image.tif')
)
I'm a hapless caveman when it comes to http, and so when the binary content gets POSTed, the mime-type becomes something like 'multipart/form-data;boundary=1BEF0A57BE110FD467A'. I'm clearly missing something in the http:request but... I don't know what. Any suggestions? It seems like I need some training wheels here, but I'm not sure which ones. :) Thank you, in advance, for your time and trouble. Best, Bridger
BD
Bridger Dyson-Smith21 May 2020 07:36 #
Hi all - Well... after staggering around and clutching my head for a few hours I realized that I didn't need the multipart at all (tricked by tricky API documentation, once again!).
http:send-request(
<http:request method='POST' username='{$user}' password='{$pass}'
    auth-method='Basic' send-authorization='true'>
  <http:header name='Content-Type' value='{$content-type}'/>
  <http:body media-type='{$content-type}'/>
</http:request>,
'http
://localhost:8080/fedora/objects/tdh:2/datastreams/OBJ?versionable=true?dsLocation=/path/to/my/
image.tif',
file:read-binary('/path/to/my/image.tif')
)
is working great. Have a lovely day and/or night. Best, Bridger
Quoted text · Bridger Dyson-Smith · 33 lines
On Wed, May 20, 2020 at 5:40 PM Bridger Dyson-Smith <bdysonsmith at gmail.com> wrote: > Hi all - > > I'm trying to use BaseX to POST an image to a digital asset management > system (i.e. I'm not using RESTXQ, etc, just using BaseX to compose and > send the request). > > The request: > http:send-request( > <http:request method='POST' username='{$user}' password='{$pass}' > auth-method='Basic' send-authorization='true'> > <http:multipart media-type='multipart/form-data'> > <http:body media-type='image/tiff'/> > </http:multipart> > </http:request>, > ' > http://localhost:8080/fedora/objects/tdh:2/datastreams/OBJ?versionable=true?dsLocation=/path/to/my/image.tif > ', > file:read-binary('/path/to/my/image.tif') > ) > > I'm a hapless caveman when it comes to http, and so when the binary > content gets POSTed, the mime-type becomes something like > 'multipart/form-data;boundary=1BEF0A57BE110FD467A'. I'm clearly missing > something in the http:request but... I don't know what. > > Any suggestions? It seems like I need some training wheels here, but I'm > not sure which ones. :) > Thank you, in advance, for your time and trouble. > Best, > Bridger >

⚡Generated with XQuery