Answers.Body: <p>For anyone interested, I figured out that I had to name the asset field as &quot;assets-upload&quot; in order for it to work. I found this out by inspecting the asset upload button in the CP. Here is my working form code:</p>
  <pre><code>          &lt;form method='post' accept-charset='UTF-8' enctype='multipart/form-data'&gt;
              {{ csrfInput() }}
              {{ actionInput('assets/upload') }}
              {{ hiddenInput('folderId', 7) }}
              {{ hiddenInput('title', 'cool image')}}
              &lt;input name=&quot;assets-upload&quot; type='file'&gt;
              &lt;input type='submit' value='submit'&gt;
            &lt;/form&gt;
  </code></pre>
  <p>And remember, you can get your intended folderId also by inspecting the volume folders in the CP to see what the ID is.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-12T05:58:51.317Z
Answers.Text: I'm also trying to use a frontend form to set a custom field on an asset upload. Where you able to get that part to work? My asset is uploading fine, using this approach. But I can't get it to save a value to the asset's custom field.
Answers.UserDisplayName: Michael Todd
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-14T14:21:44.350Z
Answers.Text: @MichaelTodd were you using 'fields[yourFieldName]' (or 'fields[yourFieldName][]' if it's a relational field) as the field name?
Answers.UserDisplayName: Brimby
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-09T23:53:29.377Z
Answers.LastActivityDate: 2020-08-09T23:53:29.377Z
Answers.UserDisplayName: Brimby
Answers.Body: <p>There is indeed an <code>assets/save-asset</code> controller. You will find it in <code>vendor/craftcms/cms/src/controllers/AssetsController.php</code>, the <code>actionSaveAsset()</code> function.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-08T04:47:15.123Z
Answers.Text: Ok great. For some reason I have a hard time reading the controller docs compared to other class docs. What is the `name` that I would need to use on my file upload field to place the file into the created asset element? If the answer is `file` then I suppose I should have tried to guess my way through this one lol.
Answers.UserDisplayName: Brimby
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-08T05:25:49.303Z
Answers.Text: I edited my question to show where I'm at now. I was able to find the folderId by inspecting the folder in the CP.
Answers.UserDisplayName: Brimby
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-08T04:38:22.757Z
Answers.LastActivityDate: 2020-08-08T04:38:22.757Z
Answers.UserDisplayName: Marion Newlevant
Body: <p>I have read <a href="https://craftcms.com/docs/3.x/assets-fields.html#creating-new-assets" rel="nofollow noreferrer">this resource</a> about uploading a file to an asset field on an entry, but I believe I need to create the asset on its own because the asset has 2 custom fields associated with it that I want to define upon its creation. Is there not something like an 'assets/save-asset' action I can use to save an asset element without having to attach it to an entry?</p>
  <p>Update: With Marion's help I'm a little closer. Side note: apparently 'assets/save-asset' is now depreciated in favor of 'assets/upload' so I'm using that. Here is my form:</p>
  <pre><code>              &lt;form method='post' accept-charset='UTF-8' enctype='multipart/form-data'&gt;
                  {{ csrfInput() }}
                  {{ actionInput('assets/upload') }}
                  {{ hiddenInput('folderId', 7) }}
                  {{ hiddenInput('title', 'cool image')}}
                  &lt;input name='file' type='file'&gt;
                  &lt;input type='submit' value='submit'&gt;
                &lt;/form&gt;
  </code></pre>
  <p>But I am now getting a 400 Bad Request error with the message <code>No file was uploaded</code>. What am I doing wrong to not have my file attach correctly?</p>
  
Tags: <assets><frontend-form>
Title: How to upload asset element on its own, not into an asset field (frontend form)
ThreadText: # How to upload asset element on its own, not into an asset field (frontend form)
  
  (Asked by: username_0 on 2020-08-08)
  
  I have read [this resource](https://craftcms.com/docs/3.x/assets-fields.html#creating-new-assets) about uploading a file to an asset field on an entry, but I believe I need to create the asset on its own because the asset has 2 custom fields associated with it that I want to define upon its creation. Is there not something like an 'assets/save-asset' action I can use to save an asset element without having to attach it to an entry?
  
  Update: With username_2's help I'm a little closer. Side note: apparently 'assets/save-asset' is now depreciated in favor of 'assets/upload' so I'm using that. Here is my form:
  
  ```
                <form method='post' accept-charset='UTF-8' enctype='multipart/form-data'>
                  {{ csrfInput() }}
                  {{ actionInput('assets/upload') }}
                  {{ hiddenInput('folderId', 7) }}
                  {{ hiddenInput('title', 'cool image')}}
                  <input name='file' type='file'>
                  <input type='submit' value='submit'>
                </form>
  
  ```
  
  But I am now getting a 400 Bad Request error with the message `No file was uploaded`. What am I doing wrong to not have my file attach correctly?
  
  **Tags:** assets, frontend-form
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2020-08-09. Score: 1 | Accepted answer
  
  For anyone interested, I figured out that I had to name the asset field as "assets-upload" in order for it to work. I found this out by inspecting the asset upload button in the CP. Here is my working form code:
  
  ```
            <form method='post' accept-charset='UTF-8' enctype='multipart/form-data'>
              {{ csrfInput() }}
              {{ actionInput('assets/upload') }}
              {{ hiddenInput('folderId', 7) }}
              {{ hiddenInput('title', 'cool image')}}
              <input name="assets-upload" type='file'>
              <input type='submit' value='submit'>
            </form>
  
  ```
  
  And remember, you can get your intended folderId also by inspecting the volume folders in the CP to see what the ID is.
  
  > **Comments:**
  > **username_1**: I'm also trying to use a frontend form to set a custom field on an asset upload. Where you able to get that part to work? My asset is uploading fine, using this approach. But I can't get it to save a value to the asset's custom field.  
  > **username_0**: @username_1 were you using 'fields[yourFieldName]' (or 'fields[yourFieldName][]' if it's a relational field) as the field name?  
  
  ---
  
  ### Answer by username_2 on 2020-08-08. Score: 2
  
  There is indeed an `assets/save-asset` controller. You will find it in `vendor/craftcms/cms/src/controllers/AssetsController.php`, the `actionSaveAsset()` function.
  
  > **Comments:**
  > **username_0**: Ok great. For some reason I have a hard time reading the controller docs compared to other class docs. What is the `name` that I would need to use on my file upload field to place the file into the created asset element? If the answer is `file` then I suppose I should have tried to guess my way through this one lol.  
  > **username_0**: I edited my question to show where I'm at now. I was able to find the folderId by inspecting the folder in the CP.  
  
  ---
  
  