Reputation: 75
Hoping I can get some help here. I am able to upload image files via the API, and I receive a file_id as a response, but every time I try to update an image field in an item using the id that was returned I get:
"File with mimetype application/octet-stream is not allowed, must match one of (MimeTypeMatcher('image', ('png', 'x-png', 'jpeg', 'pjpeg', 'gif', 'bmp', 'x-ms-bmp')),)
I've even added a line of code into my PHP script to pull the jpeg from file, rewrite it as a jpeg to be certain ( imagejpeg()) before uploading. Still, when I get to the point of updating the image field on the item, I get the same error. It seems all images uploaded via the API are converted to octet-stream. How do I get around this? I'm using the Podio PHP library.
The PHP code is as follows:
$fileName = "testUpload.jpeg";
imagejpeg(imagecreatefromstring(file_get_contents($fileName)),$fileName);
$goFile = PodioFile::upload($fileName,$itemID);
$fileID = $goFile->file_id;
PodioItem::update((int)$itemID, array(
'fields' => array(
"logo" => (int)$fileID,
)
) , array(
"hook" => 0
));
Upvotes: 0
Views: 498
Reputation: 2013
Please try and replace :
$goFile = PodioFile::upload($fileName,$itemID);
with something like:
$goFile = PodioFile::upload('/path/to/example/file/example.jpg', 'example.jpg');
$fileID = $goFile->file_id;
PodioItem::update((int)$itemID, array(
'fields' => array(
"logo" => array((int)$fileID),
)
As it is described in https://developers.podio.com/examples/files#subsection_uploading
And then use $fileID
as you've used. And yes, filename
should have file extension as well, so it will not work with just 123123123
but should work well with 123123123.jpg
Upvotes: 1