Forum

Thread tagged as: Problem, Api, Runway

Appending image data from import not working

Hi,

This is my first perch project and I've been required to do a large data import for this (we have purchased Perch runway). I've been using the Import API to build up collections. From a data point of view, everything has gone very well, so thanks for that but regarding the assets - I can also add these to the system without issue, but assigning them to the relevant post isn't working.

In my template file I have this:

<perch:content id="image" type="image" label="Upload image" >

and in the import script i've been writing I have this:

    $API      = new PerchAPI(1.0, 'my_importer');
    $Importer = $API->get('CollectionImporter');
    $Importer->set_collection('Team');

    $Template = $API->get('Template');
    $Template->set('content/team', 'content');
    $Importer->set_template($Template);
    foreach($collection as $record):
    try {
        $assetImporter = $API->get('AssetImporter');

        $image = $assetImporter->add_item([
            'type'   => 'image',
            'bucket' => 'default',
            'path'   =>  __DIR__.$record->image_full_url, //which is a local upload path ie uploads/2018-08-20/foo.jpg
        ]);

        $data = [
            'first_name'    => $record->first_name,
            'last_name'     => $record->last_name,
            'email'     => $record->email,
            'phone'     => $record->phone,
            'bio'     => $record->bio,
            'image_assetID'     => $image['id']
        ];
        $Importer->add_item($data);    
    } catch (Exception $e) {
        die('Error: '.$e->getMessage());
    }
endforeach;

When I run the above script, I import all the $collection data without issue and the image attached gets added to the system also and appears in the media library, but 'image_assetID' => $image['id'] fails to attach the image to the record. I have a few hundred records I need to apply this too, so I need to get it working please. Can anyone help?

Thanks

PS Here is my diagnostic information:

Perch Runway: 3.1.2, PHP: 7.1.14-1+ubuntu14.04.1+deb.sury.org+1, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $, with PDO
Server OS: Linux, apache2handler
Installed apps: content (3.1.2), assets (3.1.2), categories (3.1.2)
App runtimes: <?php $apps_list = [ ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /MYPATH//perch
PERCH_CORE: /MYPATH/perch/core
PERCH_RESFILEPATH: / MYPATH/perch/resources
Image manipulation: GD Imagick
PHP limits: Max upload 10M, Max POST 8M, Memory: 128M, Total max file upload: 8M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
HTTP_HOST: finnandcompany.cubeweb.co
DOCUMENT_ROOT: /MYPATH/finnandcompany
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Phil Judge

Phil Judge 0 points

  • 2 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

Hi Phil,

In your data array, try adding:

'image' => '',
'image_assetID' => $image['id']

See if that helps...

Duncan Revell said:

Hi Phil,

In your data array, try adding:

‘image’ => ‘’,
'image_assetID' => $image['id']

See if that helps...

Thank you! That's taken care of it. Appreciate your help