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:
- 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.
- 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.
- I get a notification despite of the fact that the file doesn't seems to be uploaded to the current item.
- Each file is processed separately.
Does anyone encountered that issue?
-
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
-
<?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 ) ); } ?>
-
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?
-
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?
-
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!
-
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.
-
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.
Please sign in to leave a comment.
Comments
12 comments