Skip to content

Commit e4093f0

Browse files
committed
Added file upload for attachments
1 parent db28177 commit e4093f0

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

lib/Redmine/Api/Attachment.php

+12
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,16 @@ public function show($id)
2121
{
2222
return $this->get('/attachments/'.urlencode($id).'.json');
2323
}
24+
25+
/**
26+
* Upload a file to redmine
27+
* @link http://www.redmine.org/projects/redmine/wiki/Rest_api#Attaching-files
28+
*
29+
* @param string $attachment the attachment content
30+
* @return array information about the attachment
31+
*/
32+
public function upload($attachment)
33+
{
34+
return $this->post('/uploads.json', $attachment);
35+
}
2436
}

lib/Redmine/Client.php

+6
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ private function runRequest($path, $method = 'GET', $data = '')
272272
));
273273
}
274274

275+
if ('/uploads.json' === $path || '/uploads.xml' === $path) {
276+
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
277+
'Content-Type: application/octet-stream',
278+
));
279+
}
280+
275281
switch ($method) {
276282
case 'POST':
277283
curl_setopt($curl, CURLOPT_POST, 1);

0 commit comments

Comments
 (0)