Body: <p>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.</p>
  <p>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.</p>
  <p>In my first load of these entries, I was able to successfully map the Assets fields using the following code:</p>
  <pre><code>$assets = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset);
  $assets-&gt;filename = $referenceFile-&gt;filename;
  $assets-&gt;limit = 1;
  
  foreach ($assets as $assetMatched)
      $assetId = $assetMatched-&gt;id;
  
  $assetsToSave[] = $assetId;
  
  if ($saveAssets)
      $entryToSave-&gt;getContent()-&gt;referenceItemFiles = $assetsToSave;
  </code></pre>
  <p>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:</p>
  <blockquote>
  <p>S3Exception</p>
  <p>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.</p>
  <p>/Users/markreeves/Projects/Clients/40Act.com/craft_site/craft/app/lib/S3.php(816)</p>
  </blockquote>
  <p>Based on a) the <code>copyObject</code> text and b) the <code>_1</code> in the second filename, I'm now concerned. My question:</p>
  <p>What's being done here when I save a new or existing entry in plugin code that includes an Assets field?</p>
  <p>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.</p>
  <p>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.</p>
  <p><strong>Update:</strong> 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 <code>--</code> in the filenames with <code>-</code>, removed <code>,</code>, etc.</p>
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-19T08:26:07.533Z
Comments.Text: 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 :)
Comments.UserDisplayName: Andris Sevcenko
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-19T13:13:56.770Z
Comments.Text: 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.
Comments.UserDisplayName: Mark J. Reeves
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-19T13:49:02.173Z
Comments.Text: 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 ;)
Comments.UserDisplayName: Andris Sevcenko
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-19T17:46:30.643Z
Comments.Text: On its way, Andris! - Mark
Comments.UserDisplayName: Mark J. Reeves
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-26T14:28:53.850Z
Comments.Text: 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.
Comments.UserDisplayName: joep
Tags: <plugin-development><assets><s3><saving>
Title: Saving entries in plugin: How are Assets relations handled?
ThreadText: # Saving entries in plugin: How are Assets relations handled?
  
  (Asked by: username_0 on 2015-10-16)
  
  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:
  
  > S3Exception
  >
  > 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.
  >
  > /Users/markreeves/Projects/Clients/40Act.com/craft\_site/craft/app/lib/S3.php(816)
  
  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.
  
  Thanks!
  
  **Tags:** plugin-development, assets, s3, saving
  
  > **Comments:**
  > **username_1**: 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 :)  
  > **username_0**: Thanks, username_1! 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.  
  > **username_1**: 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 ;)  
  > **username_0**: On its way, username_1! - Mark  
  > **username_2**: 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.  
  
  ---
  
  ## 0 answers
  
  