API image upload to Image Field

Answered

Comments

6 comments

  • Andreas Haugstrup Pedersen

    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

    1
    Comment actions Permalink
  • Irwan Widarto

    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

     

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    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

    0
    Comment actions Permalink
  • Irwan Widarto

    Hi Andreas,

    Ah ok, I think I understand how this works now. 

    Many thanks for your help.

    Irwan

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    Pull requests would be most welcome. Hint hint :)

    0
    Comment actions Permalink
  • Samson Burton

    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.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk