Answers.Body: <p>This ended up being a Craft bug. We just released <a href="http://buildwithcraft.com/updates#build2562" rel="nofollow">Craft 2.1 build 2562</a> with a fix.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-08T07:21:39.603Z
Answers.Text: I just updated to Craft Pro 2.1.2563 and can confirm the code posted above now works.
Answers.UserDisplayName: Ben Parizek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-01T22:33:37.617Z
Answers.LastActivityDate: 2014-07-01T22:33:37.617Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm trying to submit an Entry programmatically from the front end.  Everything works flawlessly, except, the asset fields never save.  I've dug and dug through the Entries, Elements, and Content Services.  Through similar Controllers; the Element Model.  I can't find any errors, and no matter what I do, nothing seems to happen with Assets.  Any ideas?</p>
  
  <p>This is a simplified version of my html form:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form method="post" action="" accept-charset="utf-8" enctype="multipart/form-data"&gt;
      &lt;input type="hidden" name="action" value="plugin/save/saveEntry"&gt;
  
      &lt;input type="hidden" name="title" value="Woo hoo"&gt;
      &lt;input type="hidden" name="authorId" value="1"&gt;
      &lt;input type="hidden" name="sectionId" value="10"&gt;
      &lt;input type="hidden" name="locale" value="en_us"&gt;
  
      &lt;input type="hidden" name="fields[matrixField]" value=""&gt;
      &lt;input type="hidden" name="fields[matrixField][new1][type]" value="imageBlock"&gt;
  
      &lt;h4&gt;Upload Your Photo&lt;/h4&gt;
      &lt;input type="hidden" name="fields[matrixField][new1][fields][image]" value=""&gt;
      &lt;input type="file" name="fields[matrixField][new1][fields][image][]" /&gt;
  
      &lt;button&gt;Submit&lt;/button&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>And here's a simplified version of my Controller/Service (all jammed in the Controller for the convenience of sharing)</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  namespace Craft;
  
  class Plugin_SaveController extends BaseController
  {
      public function actionSaveEntry()
      {       
          $this-&gt;requirePostRequest();
  
          // Fields
          $entry = new EntryModel();
          $entry-&gt;sectionId  = 10;
          $entry-&gt;typeId     = 11;
          $entry-&gt;locale     = 'en_us';
          $entry-&gt;postDate   = date('Y-m-d');
          $entry-&gt;authorId   = 1;
  
          // Tell our content model where to look for custom fields
          $entry-&gt;setContentFromPost('fields');
  
          // Content
          $entry-&gt;getContent()-&gt;title = "Fancy Title";
  
          // Save the entry content
          craft()-&gt;entries-&gt;saveEntry($entry);
  
          $this-&gt;redirectToPostedUrl();
  
      }
  }
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-28T06:10:36.137Z
Comments.Text: This is more about something popping out at me versus me actually knowing what's wrong but, is this suppose to be here? Highlighted with asterisks `<input type="file" name="fields[matrixField][new1][fields][image]*[]*" />`
Comments.UserDisplayName: Natetronn
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-28T11:49:29.770Z
Comments.Text: Looks right to me. Are you able to upload files to the field within the CP, by dragging-and-dropping files directly onto your Assets field within the Matrix field?
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-28T14:39:27.333Z
Comments.Text: Is it a typo that the method is called actionSaveUser and the logic is saving an entry?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-28T15:39:17.353Z
Comments.Text: I'm about 70% sure this is going to end up being a bug, but have pinged Brandon and Andris for a few clarifications.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-28T16:03:16.950Z
Comments.Text: Yes, I can upload by dragging and dropping.  I can also confirm, this works with a single assets field, it's just the Matrix that it doesn't work with. It's also not a typo with 'actionSaveUser', that's just a mistake in my simplification of the problem.  The reason I need to do this is because we are trying to register a user and save a separate Entry for that same user in a single form.  I'll update the example above so the typo doesn't exist here.  But good catch!
Comments.UserDisplayName: Ben Parizek
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-04T18:17:51.783Z
Comments.Text: Just tested locally and latest build, Ben and it's working for me now.
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><assets><plugins>
Title: How do I save a Matrix field with an asset block programmatically?
ThreadText: # How do I save a Matrix field with an asset block programmatically?
  
  (Asked by: username_0 on 2014-06-28)
  
  I'm trying to submit an Entry programmatically from the front end. Everything works flawlessly, except, the asset fields never save. I've dug and dug through the Entries, Elements, and Content Services. Through similar Controllers; the Element Model. I can't find any errors, and no matter what I do, nothing seems to happen with Assets. Any ideas?
  
  This is a simplified version of my html form:
  
  ```html
  <form method="post" action="" accept-charset="utf-8" enctype="multipart/form-data">
      <input type="hidden" name="action" value="plugin/save/saveEntry">
  
      <input type="hidden" name="title" value="Woo hoo">
      <input type="hidden" name="authorId" value="1">
      <input type="hidden" name="sectionId" value="10">
      <input type="hidden" name="locale" value="en_us">
  
      <input type="hidden" name="fields[matrixField]" value="">
      <input type="hidden" name="fields[matrixField][new1][type]" value="imageBlock">
  
      <h4>Upload Your Photo</h4>
      <input type="hidden" name="fields[matrixField][new1][fields][image]" value="">
      <input type="file" name="fields[matrixField][new1][fields][image][]" />
  
      <button>Submit</button>
  
  </form>
  
  ```
  
  And here's a simplified version of my Controller/Service (all jammed in the Controller for the convenience of sharing)
  
  ```php
  <?php
  namespace Craft;
  
  class Plugin_SaveController extends BaseController
  {
      public function actionSaveEntry()
      {       
          $this->requirePostRequest();
  
          // Fields
          $entry = new EntryModel();
          $entry->sectionId  = 10;
          $entry->typeId     = 11;
          $entry->locale     = 'en_us';
          $entry->postDate   = date('Y-m-d');
          $entry->authorId   = 1;
  
          // Tell our content model where to look for custom fields
          $entry->setContentFromPost('fields');
  
          // Content
          $entry->getContent()->title = "Fancy Title";
  
          // Save the entry content
          craft()->entries->saveEntry($entry);
  
          $this->redirectToPostedUrl();
  
      }
  }
  
  ```
  
  **Tags:** plugin-development, assets, plugins
  
  > **Comments:**
  > **username_1**: This is more about something popping out at me versus me actually knowing what's wrong but, is this suppose to be here? Highlighted with asterisks `<input type="file" name="fields[matrixField][new1][fields][image]*[]*" />`  
  > **username_2**: Looks right to me. Are you able to upload files to the field within the CP, by dragging-and-dropping files directly onto your Assets field within the Matrix field?  
  > **username_3**: Is it a typo that the method is called actionSaveUser and the logic is saving an entry?  
  > **username_3**: I'm about 70% sure this is going to end up being a bug, but have pinged username_2 and Andris for a few clarifications.  
  > **username_0**: Yes, I can upload by dragging and dropping.  I can also confirm, this works with a single assets field, it's just the Matrix that it doesn't work with. It's also not a typo with 'actionSaveUser', that's just a mistake in my simplification of the problem.  The reason I need to do this is because we are trying to register a user and save a separate Entry for that same user in a single form.  I'll update the example above so the typo doesn't exist here.  But good catch!  
  > **username_3**: Just tested locally and latest build, Ben and it's working for me now.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-07-01. Score: 4 | Accepted answer
  
  This ended up being a Craft bug. We just released [Craft 2.1 build 2562](http://buildwithcraft.com/updates#build2562) with a fix.
  
  > **Comments:**
  > **username_0**: I just updated to Craft Pro 2.1.2563 and can confirm the code posted above now works.  
  
  ---
  
  