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

Can't add attachments to card #3

Closed
mariuswilms opened this issue Oct 19, 2015 · 5 comments
Closed

Can't add attachments to card #3

mariuswilms opened this issue Oct 19, 2015 · 5 comments

Comments

@mariuswilms
Copy link

I need to add attachments/files to an existing card. I've tried the following and get a 400 Bad Request response, for each.

$client->addCardAttachment($card->id, ['file' => '/path/to/an/image.png']);
$client->addCardAttachment($card->id, ['file' => '@/path/to/an/image.png']);
$client->addCardAttachment($card->id, ['file' => fopen('/path/to/an/image.png', 'rb')]);

$client->addCardAttachment($card->id, [
'multipart' => [
  ['name' => 'file', 'contents' => fopen('/path/to/an/image.png', 'rb')]
]]);

http://docs.guzzlephp.org/en/latest/quickstart.html?highlight=multipart#sending-form-files
https://developers.trello.com/advanced-reference/card#post-1-cards-card-id-or-shortlink-attachments

@mariuswilms mariuswilms changed the title Can't add attachments to a card Can't add attachments to card Oct 19, 2015
@stevenmaguire
Copy link
Owner

Yikes! I will take a look.

@stevenmaguire
Copy link
Owner

There was in fact some code that needed to change to make this work as expected. I've added this code and updated the test suite. A new release has been cut for this, 0.3.5. Please update your project and give it a try again.

The file attribute will accept a resource, as demonstrated below, a string that represents an object in php://temp, or an instance of Psr\Http\Message\StreamInterface.

$attributes = [
    'name' => 'Cheddar Bo is delicious!',
    'file' => fopen('/path/to/cheddar-bo.jpg', 'r'),
    'mimeType' => 'image/jpeg',
    'url' => null
];

$result = $client->addCardAttachment($cardId, $attributes);

@mariuswilms
Copy link
Author

This is great - thanks a lot.

@mariuswilms
Copy link
Author

Works!

@stevenmaguire
Copy link
Owner

Hooray! Happy attaching!

prance

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

2 participants