File tree Expand file tree Collapse file tree 5 files changed +24
-5
lines changed
Expand file tree Collapse file tree 5 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 213213// Attachments
214214$ client ->api ('attachment ' )->show ($ attachmentId );
215215
216+ $ file_content = $ client ->api ('attachment ' )->download ($ attachmentId );
217+ file_put_contents ('example.png ' , $ file_content );
218+
216219// ----------------------------
217220// News
218221$ client ->api ('news ' )->all ('test ' );
Original file line number Diff line number Diff line change @@ -44,9 +44,9 @@ public function lastCallFailed()
4444 *
4545 * @return array
4646 */
47- protected function get ($ path )
47+ protected function get ($ path, $ decode = true )
4848 {
49- return $ this ->client ->get ($ path );
49+ return $ this ->client ->get ($ path, $ decode );
5050 }
5151
5252 /**
Original file line number Diff line number Diff line change @@ -22,6 +22,17 @@ public function show($id)
2222 return $ this ->get ('/attachments/ ' .urlencode ($ id ).'.json ' );
2323 }
2424
25+ /**
26+ * Get attachment content as a binary file
27+ *
28+ * @param string $id the attachment number
29+ * @return string the attachment content
30+ */
31+ public function download ($ id )
32+ {
33+ return $ this ->get ('/attachments/ ' .urlencode ($ id ), false );
34+ }
35+
2536 /**
2637 * Upload a file to redmine
2738 * @link http://www.redmine.org/projects/redmine/wiki/Rest_api#Attaching-files
Original file line number Diff line number Diff line change @@ -146,15 +146,20 @@ public function getUrl()
146146
147147 /**
148148 * HTTP GETs a json $path and tries to decode it
149- * @param string $path
149+ * @param string $path
150+ * @param boolean $decode
150151 * @return array
151152 */
152- public function get ($ path )
153+ public function get ($ path, $ decode = true )
153154 {
154155 if (false === $ json = $ this ->runRequest ($ path , 'GET ' )) {
155156 return false ;
156157 }
157158
159+ if (!$ decode ) {
160+ return $ json ;
161+ }
162+
158163 return $ this ->decode ($ json );
159164 }
160165
Original file line number Diff line number Diff line change 44
55class TestUrlClient extends Client
66{
7- public function get ($ path )
7+ public function get ($ path, $ decode = true )
88 {
99 return $ this ->runRequest ($ path , 'GET ' );
1010 }
You can’t perform that action at this time.
0 commit comments