-
Notifications
You must be signed in to change notification settings - Fork 259
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
Uploading attachments #32
Comments
My issue isn't relating to downloading PDFs, or other existing invoice attachments. I'm referring more to the ability to POST a brand new attachment to the Attachments endpoint as per http://developer.xero.com/documentation/api/attachments/ |
Yep - I'm about to push a fix for both. |
You can use it like this: $attachment = \XeroPHP\Models\Accounting\Attachment::createFromLocalFile('image.jpg');
$invoice = $xero->loadByGUID('Accounting\\Invoice', '[GUID]');
$invoice->addAttachment($attachment); and fetch them like: $invoice = $xero->loadByGUID('Accounting\\Invoice', '[GUID]');
$attachments = $invoice->getAttachments();
...
$attachment->getContent(); //Will contain the binary content of the file. Let me know if you fun into any issues. |
Just checked out the latest version, and having an issue with the file that gets created within Xero. Using the exact same code that you've posted above, I can see the file gets created in Xero as can see it is listed along with the invoice that I've associated it to. However, when I try to view the attachment (via the code above, or even directly within Xero) I get either a blank white document, or 'Failed to load PDF document'. I've tried three different PDF documents, each from different sources. Edit I've just tried with a jpg too, with no joy. |
Hey, I've just been doing some testing too, and I'm getting the same thing. The |
Whilst trying to debug what may be going on, I noticed the '?IncludeOnline=true' flag:
However, when appending that to the endpoint url the request throws an Exception The |
No, (neither is the print_r in there!). No idea how that slipped through, I think it's to do with the content-encoding - it's uploading it as UTF-8, when it's binary. |
You need to use |
I've tried now using the file handle directly as |
How are you setting the headers? Within
before the |
Given I have an existing invoice, how would I add an attachment to that invoice?
There is no attachment model, and looking at the
Save()
method on theApplication
class, there's no way for the file to be saved that I can determine.The text was updated successfully, but these errors were encountered: