Answers.Body: <p>"content" needs to be a string if using that - it represents the actual attachment contents. What you probably want is the move-file one. If you're at /civicrm/api in the explorer click on the Code Docs tab at the top and pick Attachment for the Entity, then at the bottom of the text that appears is an example, just yours is slightly different since it's a custom field.</p>
  
  <p>Also some assorted samples in here, e.g. <a href="https://github.com/civicrm/civicrm-core/blob/5.14/tests/phpunit/api/v3/AttachmentTest.php#L91" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/5.14/tests/phpunit/api/v3/AttachmentTest.php#L91</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-29T03:59:15.620Z
Answers.Text: Thanks for your guidance. I suspected something was up with the 'content' parameter because all the examples showed text. It would be _helpful_ if the documentation actually said a bit more in most places...
  
  used `'options' => [ 'move-file' => $_FILES['image']['tmp_name'] ]`
Answers.UserDisplayName: repertor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-28T23:40:42.233Z
Answers.LastActivityDate: 2019-06-28T23:40:42.233Z
Answers.UserDisplayName: Demerit
Body: <p>I'm working on a file upload of an image with a registration form. The file is being passed to PHP correctly, and I can check its properties in the $_FILES variable. I used the API Explorer to get the code example below. This question (<a href="https://civicrm.stackexchange.com/questions/12028/uploading-files-through-the-api/12123#12123">Uploading files through the API</a>) touches on this, but the answer just directs the person to the API Explorer.</p>
  
  <p><code>$result['attachment'] = civicrm_api3('Attachment', 'create', [
      'name' =&gt; $name,
      'mime_type' =&gt; $_FILES['image']['type'],
      'entity_id' =&gt; $result['contact']['id'],
      'field_name' =&gt; 'custom_3',
      'content' =&gt; $_FILES['image'],
  ]);</code></p>
  
  <p>The error I receive is:
  <code>Mandatory key(s) missing from params array: 'id' or 'content' or 'options.move-file'</code>
  but I have no idea what this means. <code>content</code> is set in the params. This API call happens after a working sequence of creating a Contact, Address, Email, Websites, and more for the signup. I can find no other guidance on completing this.</p>
  
Tags: <api><php><attachments>
Title: Attachment API File Upload
ThreadText: # Attachment API File Upload
  
  (Asked by: username_0 on 2019-06-28)
  
  I'm working on a file upload of an image with a registration form. The file is being passed to PHP correctly, and I can check its properties in the $\_FILES variable. I used the API Explorer to get the code example below. This question ([Uploading files through the API](https://civicrm.stackexchange.com/questions/12028/uploading-files-through-the-api/12123#12123)) touches on this, but the answer just directs the person to the API Explorer.
  
  `$result['attachment'] = civicrm_api3('Attachment', 'create', [
  'name' => $name,
  'mime_type' => $_FILES['image']['type'],
  'entity_id' => $result['contact']['id'],
  'field_name' => 'custom_3',
  'content' => $_FILES['image'],
  ]);`
  
  The error I receive is:
  `Mandatory key(s) missing from params array: 'id' or 'content' or 'options.move-file'`
  but I have no idea what this means. `content` is set in the params. This API call happens after a working sequence of creating a Contact, Address, Email, Websites, and more for the signup. I can find no other guidance on completing this.
  
  **Tags:** api, php, attachments
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-28. Score: 1 | Accepted answer
  
  "content" needs to be a string if using that - it represents the actual attachment contents. What you probably want is the move-file one. If you're at /civicrm/api in the explorer click on the Code Docs tab at the top and pick Attachment for the Entity, then at the bottom of the text that appears is an example, just yours is slightly different since it's a custom field.
  
  Also some assorted samples in here, e.g. <https://github.com/civicrm/civicrm-core/blob/5.14/tests/phpunit/api/v3/AttachmentTest.php#L91>
  
  > **Comments:**
  > **username_0**: Thanks for your guidance. I suspected something was up with the 'content' parameter because all the examples showed text. It would be _helpful_ if the documentation actually said a bit more in most places...  used `'options' => [ 'move-file' => $_FILES['image']['tmp_name'] ]`  
  
  ---
  
  