Reputation: 57
Working with files from a third party application in Podio is a pain.
The application i'm making is a replacement for the webform Podio provides.
In some of these webforms, i need the end-user to upload up to 5 or 6 files.
As of right now, you have to make 2 requests per file uploaded to Podio. 1 request to upload the file, and another to attach the file to the item you have created.
This is constantly hitting the PodioRateLimit.
What would be easier, is to compile all the files into 1 array and then upload and attach that.
If this is already possible please provide documentation.
Upvotes: 2
Views: 381
Reputation: 357
Here is the php working code:
$field_id = 'photos';
foreach($photos as $photo){
// Upload file
$file = PodioFile::upload("uploads/".$photo, $photo);
$fileID[] = (int)$file->file_id;
}
PodioItem::update((int)$item->item_id, array(
'fields' => array(
"photos" => $fileID
)));
Upvotes: 0
Reputation: 2013
Uploading files still have to happen one by one and Podio API doesn't support bulk files upload. Yet you don't need to have 2 requests per file uploaded to Podio. It could rather be: [number of files] + 1 request.
So, for creating new item it could be:
total number of requests: 5 (number of files + 1)
files = [<array of file names>]
file_ids = []
files.each do |filename|
uploaded_file = Podio::FileAttachment.upload(File.open(filename), File.basename(filename))
file_ids << uploaded_file.file_id
end
new_item = Podio::Item.create(<app_id>, 'fields' => {'title' => 'My title'}, 'file_ids' => file_ids)
And for updating existing item it's pretty much the same, just need to call Item.update instead of Item.create.
P.S. Sorry, but example is in Ruby and not PHP
Upvotes: 4