API image upload to Image Field
AnsweredHi,
I have an app with an Image field. Can I use the API to upload an image to this field?
I cannot find any information in the API Reference as to how to upload an image. The Files section only explains how to attach Files, which I presume is not the same as adding an Image to an Image field.
Thanks
Irwan
-
Hi Irwan,
Adding an image to an image field is a two-step process. First you must upload the file. https://developers.podio.com/doc/files/upload-file-1004361 will give you a file object with a file_id you need in step two.
Step two is to create a new item, update an item or update the field value. Here you pass the file_id as a the value for the field. We have a general tutorial on working with items here https://developers.podio.com/examples/items
Working with file_ids for image fields is not different than the other field types. Just as you use profile_ids to work with Contact fields you use file_ids to work with image fields.
Does that make sense?
/Andreas
-
Hi Andreas,
I am trying to use podiojs (!) to upload a file in Step 1...
function uploadFile() {
podiojs.post('/file/', {source: 'c:\tmp\images\m1.jpg', 'file': 'm1.jpg'}, function(response, body){
console.log(body);
});
}and getting the following error:
Express server listening on port 3000
[2013-07-01 21:00:51.302] INFO - Connection {} opened successfully
There was a problem with a request to /file/. Error was "No matching operation could be found. Missing parameters: source." (not_found)Did I get the arguments to the podiojs.post method wrong?
Thanks
Irwan
-
Hi Irwan,
The arguments look right, but I believe you are sending the filepath as a string rather than sending the actual file contents. You'll need to make some improvements to podiojs so it can read the file from the file system and encoding it properly for the upload. This appears to be a stackoverflow thread dealing with this exact problem: http://stackoverflow.com/questions/5744990/how-to-upload-a-file-from-node-js
All the best,
Andreas -
Hoping I can get some help here. I am able to follow this process to upload image files, receiving a file_id, but every time I try to update the 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 ( 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 PHP library.
Please sign in to leave a comment.
Comments
6 comments