Answers.Body: <p>There's a unit test at <a href="https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L93-L100" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L93-L100</a> and <a href="https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L316-L319" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L316-L319</a> that together describe how to use this. Putting them together it would be:</p>
  <pre><code>civicrm_api3('Attachment', 'create', [
    'entity_table' =&gt; 'civicrm_activity',
    'entity_id' =&gt; $activityId,
    'name' =&gt; 'example.png',
    'mime_type' =&gt; 'image/png',
    'description' =&gt; 'My test description',
    'options' =&gt; [
      'move-file' =&gt; 'temporary/path/to/example.png',
    ],
  ]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-02T13:57:31.737Z
Answers.LastActivityDate: 2023-05-02T13:57:31.737Z
Answers.UserDisplayName: Demerit
Body: <p>I tried many things like base 64 or just using the php function <code>file_get_contents</code> but when i check the civicrm UI and click on the attachment it doesn't work (for images for example it says unrecognized format).
  So what is the proper way to use the content property in the create action in the API V3
  <a href="https://i.sstatic.net/hykCU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hykCU.png" alt="enter image description here" /></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-01T16:18:36.503Z
Comments.Text: While you might be able to get it to work, I'm not sure that's what the content property was designed for. I think it was just for text. You probably need to store it in a file and then instead of content use path.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-02T11:13:30.887Z
Comments.Text: @Demerit the path property is read only, i don't think it's possible to do so if you check the database table `civicrm_file` you find no path column, instead you find the uri which is just the file name, then civicrm will do the rest and calculate the path depending only on the file name, at least that's what i understood.
Comments.UserDisplayName: abdeslam chettout
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-02T13:48:55.990Z
Comments.Text: Ah you're right. Take a look at the unit test here: https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L93-L100. The trick seems to be to use `'options' => ['move-file' ...]`, which gets used in the api call here: https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L316-L319
Comments.UserDisplayName: Demerit
Tags: <civicrm-entity><files>
Title: what is the format or encoding of files in the content property when creating an attachment entity in civicrm API V3
ThreadText: # what is the format or encoding of files in the content property when creating an attachment entity in civicrm API V3
  
  (Asked by: username_0 on 2023-05-01)
  
  I tried many things like base 64 or just using the php function `file_get_contents` but when i check the civicrm UI and click on the attachment it doesn't work (for images for example it says unrecognized format).
  So what is the proper way to use the content property in the create action in the API V3
  [![enter image description here](https://i.sstatic.net/hykCU.png)](https://i.sstatic.net/hykCU.png)
  
  **Tags:** civicrm-entity, files
  
  > **Comments:**
  > **username_1**: While you might be able to get it to work, I'm not sure that's what the content property was designed for. I think it was just for text. You probably need to store it in a file and then instead of content use path.  
  > **username_0**: @username_1 the path property is read only, i don't think it's possible to do so if you check the database table `civicrm_file` you find no path column, instead you find the uri which is just the file name, then civicrm will do the rest and calculate the path depending only on the file name, at least that's what i understood.  
  > **username_1**: Ah you're right. Take a look at the unit test here: https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L93-L100. The trick seems to be to use `'options' => ['move-file' ...]`, which gets used in the api call here: https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L316-L319  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-05-02. Score: 0
  
  There's a unit test at https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L93-L100 and https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L316-L319 that together describe how to use this. Putting them together it would be:
  civicrm_api3('Attachment', 'create', [
    'entity_table' => 'civicrm_activity',
    'entity_id' => $activityId,
    'name' => 'example.png',
    'mime_type' => 'image/png',
    'description' => 'My test description',
    'options' => [
      'move-file' => 'temporary/path/to/example.png',
    ],
  ]);
  
  
  ---
  
  