Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with attachments. #15

Open
sorintx opened this issue Aug 18, 2015 · 4 comments
Open

Issue with attachments. #15

sorintx opened this issue Aug 18, 2015 · 4 comments

Comments

@sorintx
Copy link

sorintx commented Aug 18, 2015

Can you show me please how can an attachment can be added?

Here is my current code:

$reply_upload = $client->api('cards')->attachments()->create($id_card, array(
'file' => DOCROOT.'media/uploads/issue_tracker/'.$options['filename'],
'mimeType' => File::mime_by_ext($ext),
'name' => uniqid().'.'.$ext
));

The issue is that if I put the path to the file on the file parameter .. it shows in the content of the Trello attachment but if I use file_get_contents on it, it is ok there but the mime is not set at all.

Thanks!

@xsen
Copy link

xsen commented Oct 11, 2016

        $client = new Client();
        $client->setHttpClient(new HttpClient());
        $client->authenticate(self::API_KEY, self::TOKEN, Client::AUTH_URL_CLIENT_ID);

        $client->cards()->attachments()->create($id, ['file' => $name, 'name' => basename($name)]);

and

class HttpClient extends \Trello\HttpClient\HttpClient
{
    protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array())
    {
        $path = $this->options['api_version'].'/'.$path;

        if ($httpMethod === 'GET' && $body) {
            $path .= (false === strpos($path, '?') ? '?' : '&');
            $path .= utf8_encode(http_build_query($body, '', '&'));
        }

        $request =  $this->client->createRequest(
            $httpMethod,
            $path,
            array_merge($this->headers, $headers),
            $body,
            $options
        );

        if ( isset($body['file']) )
        {
            $request = $request->addPostFiles(array('file' => $body["file"]));
        }

        return $request;
    }

}

@danrichards
Copy link

Thank you @xsen !

For those who are using using Laravel Trello, this also functions with the facade 😄 .

Trello::setHttpClient(new YourHttpClient());
Trello::authenticate(config('trello.api_key'), config('trello.api_token'), \Trello\Client::AUTH_URL_CLIENT_ID);
Trello::card()
    ->attachments()
    ->create('card_id_here', ['file' => $name, 'name' => basename($name)]);

@molerat619
Copy link

What is $name? We are trying to do this as well following Trello's docs but after the upload, Trello will only have the *.tmp files

@xsen
Copy link

xsen commented Aug 1, 2018

@molerat619 $name is file full path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants