API file upload issue

Comments

12 comments

  • Casper Fabricius

    Hi Mathieu,

    To help you debug this issue, can you please post your code and the raw requests you make to the API here?

    0
    Comment actions Permalink
  • Mathieu Smith

    Hi Casper,

    Could I sent you the code by email?

    If I do that here, the code will not be properly indented.

    I'm looking forward for your answer!

    0
    Comment actions Permalink
  • Casper Fabricius

    Hi Mathieu,

    You can use markdown to get the code properly indented as described here: https://support.zendesk.com/hc/en-us/articles/203691016-Formatting-text-with-Markdown#topic_xqx_mvc_43__row_fs1_zln_1n

    0
    Comment actions Permalink
  • Mathieu Smith
    <?php
    /*This is one webhook triggered on item.update*/
    
    //Get updated item
    $item = PodioItem::get(1234);
    
    //CODE HAS BEEN PREVIOUSLY PROCEED TO GENERATE THE FIRST PDF FILE
    //Generate unique name 'my-file'.time().'.pdf'
    process_file($item, 'my-file'.time().'.pdf', 'Customers.pdf');
    
    
    //CODE HAS BEEN PREVIOUSLY PROCEED TO GENERATE THE SECOND PDF FILE
    //Generate unique name 'my-file'.time().'.pdf'
    process_file($item, 'my-file-2'.time().'.pdf', 'Prospects.pdf');
    
    
    //Upload file to Podio item
    function process_file($item, $raw_filename, $filename){
        //Upload file
        $new_file = PodioFile::upload($raw_filename, $filename);
    
        //Attach file to current item
        PodioFile::attach(
            $new_file->file_id,
            array(
                'ref_type'  => 'item',
                'ref_id'    => (int)$item->item_id
            ),
            array(
                'hook'      => false,
                'silent'    => false
            )
        );
    }
    ?>
    
    0
    Comment actions Permalink
  • Casper Fabricius

    The code looks fine. What exactly are you sending and getting back from the API? (See http://podio.github.io/podio-php/debug/)

    You can also use the attach file operation to reorder files, that could be what happens when there's existing files on the item. Could you provide some item ids so I can take a closer look?

    0
    Comment actions Permalink
  • Mathieu Smith

    You can loook at this item_id: 350163100.

    I tried the "debug mode" and I didin't get any ouput. I put the code before any API call.

    I use the Podio-PHP lib 4.3.0.

    If you need further details please contact me.

    0
    Comment actions Permalink
  • Mathieu Smith

    Hi Casper, any update on this?

    0
    Comment actions Permalink
  • Casper Fabricius

    You need to look into the log files to see what you submit the API and what response you get back. This information will make the whole difference to pin-pointing what goes wrong.

    For the item ID you shared, I can see that 8 files with ids 195242710, 195242713, 195243179, 195243181, 195243184, 195243185, 195243350, 195243354 have been attached to the item, but they have all been deleted again.

    Is it possible that you somehow override the files assigned to the item?

    0
    Comment actions Permalink
  • Mathieu Smith

    No, I do not override the file, because each uploaded file has a different name. That way, I expect to see all attached file, because they have a different and unique name, ex. uniquid().EXT

    Also, I never call PodioFile::delete() method. Is there something on Podio API back-end which delete the uploaded file because I encounter a specific condition on your side?

    How do you hadle file upload/attachment? Is two files with the same name are different or overriden?

    Thanks!

    0
    Comment actions Permalink
  • Mathieu Smith

    Any update on this Casper?

    Note: I attached manually a file into the target item, then tried to upload a file via the API. No file has been attached to the item.

    After that try, I have deleted the manually uploaded file then triggered my webhook. The file file has been uploaded and attached successfully to the item via the webhook.

    0
    Comment actions Permalink
  • Casper Fabricius

    Hi Mathieu,

    I can't really help you any further until you provide the specific calls and responses you make to the API as I have requested. I think you might be doing something slightly different that what you think, so I need to see the concrete API interaction.

    I can tell you that if you call update item with an empty array of file ids, that would delete all the files. That could be what you are doing by mistake.

    1
    Comment actions Permalink
  • Mathieu Smith

    Thanks for your follow-up Casper.

    I was supplying an empty array, problem solved!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk