I’m populating fields on image upload with exif- and iptc-data. It works fine but only for no more than 3 images at once (files are uploaded but an error is given saying files can’t be uploaded and iptc and exif fields remain empty). When I remove the iptc-data I can upload more than 3 files (tested with 10).
I haven’t used hooks before so I must be doing something wrong with the iptc data. I’ve got a fileMethods plugin:
<?php
Kirby::plugin('myplugin/iptcmeta', [
'fileMethods' => [
'iptc' => function ($item) {
getimagesize($this->url(), $info);
if (isset($info['APP13'])) {
$iptc = iptcparse($info['APP13']);
if ($item == 'kop') {
$iptc_item = $iptc['2#105'][0];
}
if ($item == 'beschrijving') {
$iptc_item = $iptc['2#120'][0];
}
if ($item == 'locatie') {
$iptc_item = $iptc['2#092'][0];
}
# and so on …
return $iptc_item;
}
]
]);
My hook uses it like this:
<?php
Kirby::plugin('myplugin/metadata', [
'hooks' => [
'file.create:after' => function ($file) {
$file->update([
'iptc_kop' => $file->iptc('kop'),
'iptc_desc' => $file->iptc('beschrijving'),
'iptc_locatie' => $file->iptc('locatie')
# and so on …
# also exif
$time = $file->exif()->timestamp(),
'exif_date' => date('j-n-Y', $time),
'exif_timestamp' => $file->exif()->timestamp(),
'exif_date2' => $file->exif()->timestamp(),
'exif_aperture' => $file->exif()->aperture(),
# and so on …
]);
}
]
]);
I’ve adapted your suggestions (see code underneath) but no improvement max. file upload is 3. From 4 onwards eventually shows an error, ‘files can’t be uploaded’ but files do get uploaded only the meta data is missing. I might have done something wrong?
My assumption is that the script takes too long to execute with each file calling the hook. I’d try if setting php max_execution_time in your php.ini setting to a higher value makes any difference.
I have adjusted max_input_time to 60 sec with no difference also upped memory_limit from 128M to 256M without effect
Without the keywords I got error: "The JSON response could not be parsed:"
Which is something I didn’t see before, no extra info though just that. With just one iptc field didn’t make any difference. With just exif, file uploads are fast. I guess it’s just three at a time, still faster than typing out meta data again.
I could maybe request a feature for Kirby; to do iptc as it does exif?
Didn’t we check for empty in the fileMethods already, not enough?
Anyway, as a double check I’ve changed that and used the hook in a 3.5.7.1 starterkit and got the same result 3 files ok, 4 files: throws an error but files are uploaded, but no meta data.