[rt-users] 4.0.5 REST - adding an attachment - php
Thomas Sibley
trs at bestpractical.com
Wed Mar 28 22:40:50 EDT 2012
On 03/28/2012 07:40 PM, Alex Ardalich wrote:
> $params = array(
> 'http' => array(
> 'method' => 'POST',
> 'header' => 'Content-type:
> application/x-www-form-urlencoded',
> 'content' => $data
> ));
This is certainly the wrong content-type. You want a multipart content
type since uploads generally can't work url encoded.
> $postargs = array(
> 'user' => 'aardalich',
> 'pass' => 'BluesPacer',
> 'content' => $content,
> 'attachment_1' => $attachment_1
> );
You probably want to change that password now...
> // get the curl session object
> $session = curl_init($request);
>
> // set the POST options
> curl_setopt ($session, CURLOPT_POST, true);
> curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
> curl_setopt($session, CURLOPT_HEADER, true);
> curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
> curl_setopt( $session, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
I don't know enough about the PHP curl interface to tell if the POST is
getting constructed correctly by this code. Since it doesn't work,
however, I suspect it's subtly wrong.
> Expect I'm not grabbing the raw file correctly, or encoding it or
> something. Unsure of how.
The POST data needs to be a multipart MIME entity.
Look at the other language examples of POSTing attachment_1 on the wiki
page I linked to. For debugging, capture the request that's actually
sent by your code over the network. For figuring out what the POST is
supposed to look like, capture what /opt/rt4/bin/rt sends when you
submit a comment with an attachment.
Thomas
More information about the rt-users
mailing list