Post

2 followers Follow
1
Avatar

API file upload issue

Hi!

I try to upload file to an item with the PHP API and there's no file uploaded, here's an example:

  1. I update an item by the Web interface. After the item has been updated, a webhook is triggered. That webhook uploads and attachs a PDF file to the current item.
  2. If the current item has NO file, all works perfectly. In the other hand, if the item has ONE OR MORE files, the upload seems to fail.
  3. I get a notification despite of the fact that the file doesn't seems to be uploaded to the current item.
  4. Each file is processed separately.

Does anyone encountered that issue?

Mathieu Smith

Please sign in to leave a comment.

12 comments

0
Avatar

Hi Mathieu,

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

Casper Fabricius 0 votes
0
Avatar

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!

Mathieu Smith 0 votes
0
Avatar
<?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
        )
    );
}
?>
Mathieu Smith 0 votes
0
Avatar

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?

Casper Fabricius 0 votes
0
Avatar

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.

Mathieu Smith 0 votes
0
Avatar

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?

Casper Fabricius 0 votes
0
Avatar

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!

Mathieu Smith 0 votes
0
Avatar

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.

Mathieu Smith 0 votes
1
Avatar

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.

Casper Fabricius 1 vote