I'm importing an existing ExpressionEngine site's content into Craft, using content exported in XML on the EE site, and stepping through each entry.

This includes hooking up Assets files, where the Assets field/upload location is pointing to the same S3 bucket that Channel Files was on the EE site.

In my first load of these entries, I was able to successfully map the Assets fields using the following code:

$assets = craft()->elements->getCriteria(ElementType::Asset);
$assets->filename = $referenceFile->filename;
$assets->limit = 1;

foreach ($assets as $assetMatched)
    $assetId = $assetMatched->id;

$assetsToSave[] = $assetId;

if ($saveAssets)
    $entryToSave->getContent()->referenceItemFiles = $assetsToSave;

On a re-run of the import, where I check for a match on the imported entry at each pass, I began receiving an FK error on the Assets field, but I want to set that aside for now. I reverted my database and ran the 1st time import again. I'm now seeing the following error:


S3::copyObject(reference-materials, 1610-10-01-001-0000015-supertrust_final_prospectus_may_29_1992--pp_33-end.pdf, reference-materials, 1610-10-01-001-0000015-supertrust_final_prospectus_may_29_1992-pp_33-end_1.pdf): [NoSuchKey] The specified key does not exist.


Based on a) the copyObject text and b) the _1 in the second filename, I'm now concerned. My question:

What's being done here when I save a new or existing entry in plugin code that includes an Assets field?

Is Craft trying to copy files? I'm now seeing a bunch of files in my S3 bucket with today's date as timestamp, and I'm not seeing corresponding activity on the live site using the same bucket, so it seems that Craft is not just creating relations for those files, but is actually touching the files, too. This is not what I would expect.

What should I expect to happen when I map asset IDs to an Assets field based on files that already exist? I had Craft index the S3 bucket via the admin prior to running this code, so that the database has records of those files.

Update: It looks like Craft has renamed files in the existing bucket, causing them to break on the other site. Specifically, it looks like Craft has replaced -- in the filenames with -, removed ,, etc.


  • Mark, that sounds like it would make for a nice support email, especially if you include all the logs and Craft version you're using :) – Andris Sevcenko Oct 19 '15 at 8:26
  • Thanks, Andris! I'm definitely straddling a fine line between a general question and support. I can think of some workarounds for this, too, but I'm definitely seeing that Craft selectively renamed some files in the original bucket based on characters in the filenames. That right there leads me to think that I should not be repurposing the same bucket for the legacy EE site and the new Craft site, unless there's a way to disable that. If I index a cloned bucket and ignore assets on reimported entries, I'll be OK, but would still like to understand Craft's intent in this scenario. – Mark J. Reeves Oct 19 '15 at 13:13
  • Mark, that's why I wanted to get the Craft version and the like. Or just the log files, at least, so I can trace back the copy operation. Either way, this is hugely specific and is not a good question for SE, I think. Might as well continue this over email ;) – Andris Sevcenko Oct 19 '15 at 13:49
  • On its way, Andris! - Mark – Mark J. Reeves Oct 19 '15 at 17:46
  • For anyone getting a similar error: exception 'S3Exception' with message 'S3::getObject(res.website.com, path/to/file.jpg): [NoSuchKey] The specified key does not exist.' in craft/app/lib/S3.php:753 In this case, it was trying to reference a file that had somehow been deleted from s3 & it couldn't reference it. – joep Apr 26 '18 at 14:28