Answers.Body: <p>Yes, it did happen and it's called the "attachment" api. You can look up the docs for it in the api explorer:</p>
  
  <p><a href="https://i.sstatic.net/dJb5E.png" rel="noreferrer"><img src="https://i.sstatic.net/dJb5E.png" alt="enter image description here"></a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-30T14:47:00.993Z
Answers.Text: Thanks! And I confess my ignorance - does webform-civicrm use this so file uploads don't rely on the form submission not being deleted anymore?
Answers.UserDisplayName: Laryn
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-31T03:39:08.193Z
Answers.Text: It does for almost everything. The one exception is the "contact image_url" because Civi does not store an actual file in that field, just the url. So that currently is still only stored in the webform submission.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-30T14:04:09.967Z
Answers.LastActivityDate: 2016-05-30T14:04:09.967Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>Example to upload a image in custom field. Important, if you want to upload in custom field, you can't fill the <code>entity table</code>.</p>
  <p>The field need to be of type file.</p>
  <pre><code>$fields = [
    'key' =&gt;  $key,
    'api_key' =&gt; $api_key,
    'entity' =&gt; 'Attachment',
    'action' =&gt; 'create',
    'mime_type' =&gt; 'image/jpeg',
    'name' =&gt; 'test.jpg',
    'content' =&gt; file_get_contents('test.jpg'),
    'entity_id' =&gt; 2, // Contact id, contribution_id,....
    'field_name' =&gt; 'custom_247' // Custom field type file
  ];
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-15T11:28:34.447Z
Answers.LastActivityDate: 2023-02-15T11:28:34.447Z
Answers.UserDisplayName: ruben
Body: <p>I see an <a href="https://forum.civicrm.org/index.php?topic=27122.0" rel="nofollow noreferrer">older thread on the forum about potential improvements to the API to allow file uploads</a>, but I'm not sure that ever happened. Has anyone ever uploaded files in CiviCRM using the API?</p>
  
  <p>I see in the API Explorer that there is a <strong>File > Create</strong> with a parameter for <strong>File Contents</strong> but I'm not sure if you feed in the MIME contents, a URL, or...?</p>
  
  <p><a href="https://i.sstatic.net/MNuth.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MNuth.png" alt="File via API"></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-06T14:32:18.907Z
Comments.Text: fantastic, that is good to know. does anyone know if we can provide an externalized attachment storage, example s3 buckets or firebase storage ? That is easier to scale than having it on the server running civi.
Comments.UserDisplayName: Jeff Salleh
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-06-11T19:50:13.863Z
Comments.Text: I think that warrants a question of its own. Also I don't know the answer. :)
Comments.UserDisplayName: Laryn
Tags: <api><upload><files>
Title: Uploading files through the API
ThreadText: # Uploading files through the API
  
  (Asked by: username_0 on 2016-05-25)
  
  I see an [older thread on the forum about potential improvements to the API to allow file uploads](https://forum.civicrm.org/index.php?topic=27122.0), but I'm not sure that ever happened. Has anyone ever uploaded files in CiviCRM using the API?
  
  I see in the API Explorer that there is a **File > Create** with a parameter for **File Contents** but I'm not sure if you feed in the MIME contents, a URL, or...?
  
  [![File via API](https://i.sstatic.net/MNuth.png)](https://i.sstatic.net/MNuth.png)
  
  **Tags:** api, upload, files
  
  > **Comments:**
  > **username_1**: fantastic, that is good to know. does anyone know if we can provide an externalized attachment storage, example s3 buckets or firebase storage ? That is easier to scale than having it on the server running civi.  
  > **username_0**: I think that warrants a question of its own. Also I don't know the answer. :)  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-05-30. Score: 5 | Accepted answer
  
  Yes, it did happen and it's called the "attachment" api. You can look up the docs for it in the api explorer:
  
  [![enter image description here](https://i.sstatic.net/dJb5E.png)](https://i.sstatic.net/dJb5E.png)
  
  > **Comments:**
  > **username_0**: Thanks! And I confess my ignorance - does webform-civicrm use this so file uploads don't rely on the form submission not being deleted anymore?  
  > **username_2**: It does for almost everything. The one exception is the "contact image_url" because Civi does not store an actual file in that field, just the url. So that currently is still only stored in the webform submission.  
  
  ---
  
  ### Answer by username_3 on 2023-02-15. Score: 0
  
  Example to upload a image in custom field. Important, if you want to upload in custom field, you can't fill the `entity table`.
  
  The field need to be of type file.
  
  ```
  $fields = [
    'key' =>  $key,
    'api_key' => $api_key,
    'entity' => 'Attachment',
    'action' => 'create',
    'mime_type' => 'image/jpeg',
    'name' => 'test.jpg',
    'content' => file_get_contents('test.jpg'),
    'entity_id' => 2, // Contact id, contribution_id,....
    'field_name' => 'custom_247' // Custom field type file
  ];
  
  ```
  
  
  ---
  
  