Skip to content

Commit 103b10a

Browse files
author
Joan
committed
Added attachment upload filename param
1 parent e75295b commit 103b10a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Redmine/Api/Attachment.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ public function download($id)
4141
* Upload a file to redmine.
4242
*
4343
* @see http://www.redmine.org/projects/redmine/wiki/Rest_api#Attaching-files
44-
*
44+
* available $params :
45+
* filename: filename of the attachment
46+
*
4547
* @param string $attachment the attachment content
46-
*
48+
* @param array $params optional parameters to be passed to the api
4749
* @return array information about the attachment
4850
*/
49-
public function upload($attachment)
51+
public function upload($attachment, $params = [])
5052
{
51-
return $this->post('/uploads.json', $attachment);
53+
return $this->post('/uploads.json?'.http_build_query($params), $attachment);
5254
}
5355
}

src/Redmine/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public function prepareRequest($path, $method = 'GET', $data = '')
600600
private function isUploadCall($path, $data)
601601
{
602602
return
603-
('/uploads.json' === $path || '/uploads.xml' === $path) &&
603+
(preg_match('/\/uploads.(json|xml)/i', $path)) &&
604604
isset($data) &&
605605
is_file($data)
606606
;
@@ -626,7 +626,7 @@ private function setHttpHeader($path)
626626

627627
// Content type headers
628628
$tmp = parse_url($this->url.$path);
629-
if ('/uploads.json' === $path || '/uploads.xml' === $path) {
629+
if (preg_match('/\/uploads.(json|xml)/i', $path)) {
630630
$httpHeader[] = 'Content-Type: application/octet-stream';
631631
} elseif ('json' === substr($tmp['path'], -4)) {
632632
$httpHeader[] = 'Content-Type: application/json';

0 commit comments

Comments
 (0)