Answers.Body: <p>You can find a specific folder using the Assets service:</p>
  <p><a href="https://docs.craftcms.com/api/v3/craft-services-assets.html#public-methods" rel="nofollow noreferrer">https://docs.craftcms.com/api/v3/craft-services-assets.html#public-methods</a></p>
  <p>If you know all the necessary information when that template is parsed, the <a href="https://docs.craftcms.com/api/v3/craft-services-assets.html#method-findfolder" rel="nofollow noreferrer">findFolder</a> method might be useful but <a href="https://docs.craftcms.com/api/v3/craft-services-assets.html#method-ensurefolderbyfullpathandvolume" rel="nofollow noreferrer">ensureFolderByFullPathAndVolume</a> is probably more precise.</p>
  <p>For example:</p>
  <pre><code>{{ hiddenInput( 'secret_folder_id', 
      craft.app.assets.ensureFolderByFullPathAndVolume($volumePath, $assetVolume) ) }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-28T23:12:22.377Z
Answers.Text: Sorry, my request upon re-reading it might be vague. I have the folderId, the question is how tell the frontend form to make sure the asset gets uploaded specifically to that subfolder. I want something like {{ hiddenInput('folderId':44) }} but that does not work and the asset always just uploads to the parent volume, not the subfolder
Answers.UserDisplayName: AbbeyDesign
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-29T08:26:52.963Z
Answers.Text: Ok, I *think* I know what you mean. You could try changing the properties of the asset field, checking "Restrict assets to a single folder" and specifying the path to the subfolder you'd like things to save to.
Answers.UserDisplayName: Wallace
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-26T07:41:10.067Z
Answers.LastActivityDate: 2021-04-26T07:41:10.067Z
Answers.UserDisplayName: Wallace
Body: <p>In a front-end form where I am uploading a file, I need to specify a specific subfolder. I can't do it in the cp dynamic field for reasons so I was hoping to use a hidden field to set the folderId. The folderId exists and each entry has a different folder. I have this code that works but I can't figure out the code, for example something like: folderId: 44</p>
  <pre><code>&lt;form method=&quot;post&quot;&gt;
   {{ csrfInput() }}
   {{ actionInput('entries/save-entry') }}
   {{ hiddenInput('sectionId', '3') }}
   {{ hiddenInput('enabled', '1') }}
   {{ hiddenInput('entryId', entry.id) }}
   {{ hiddenInput('redirect', craft.app.request.absoluteUrl|hash) }}
  
      {% for relatedAssetId in entry.patientFiles.ids() %}
        {{ input(
            'hidden',
            'fields[patientFiles][]',
            relatedAssetId,
          ) }}
      {% endfor %}
            {{ input('file', 'fields[patientFiles][]', options={
               multiple: true,
            }) }}
      &lt;button class=&quot;btn btn-primary&quot; type=&quot;submit&quot;&gt;Upload&lt;/button&gt;
  </code></pre>
  
  
Tags: <frontend-form>
Title: Specify FolderId When Uploading a File on the Frontend
ThreadText: # Specify FolderId When Uploading a File on the Frontend
  
  (Asked by: username_0 on 2021-04-23)
  
  In a front-end form where I am uploading a file, I need to specify a specific subfolder. I can't do it in the cp dynamic field for reasons so I was hoping to use a hidden field to set the folderId. The folderId exists and each entry has a different folder. I have this code that works but I can't figure out the code, for example something like: folderId: 44
  
  ```
  <form method="post">
   {{ csrfInput() }}
   {{ actionInput('entries/save-entry') }}
   {{ hiddenInput('sectionId', '3') }}
   {{ hiddenInput('enabled', '1') }}
   {{ hiddenInput('entryId', entry.id) }}
   {{ hiddenInput('redirect', craft.app.request.absoluteUrl|hash) }}
  
      {% for relatedAssetId in entry.patientFiles.ids() %}
        {{ input(
            'hidden',
            'fields[patientFiles][]',
            relatedAssetId,
          ) }}
      {% endfor %}
            {{ input('file', 'fields[patientFiles][]', options={
               multiple: true,
            }) }}
      <button class="btn btn-primary" type="submit">Upload</button>
  
  ```
  
  **Tags:** frontend-form
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-04-26. Score: 1
  
  You can find a specific folder using the Assets service:
  
  <https://docs.craftcms.com/api/v3/craft-services-assets.html#public-methods>
  
  If you know all the necessary information when that template is parsed, the [findFolder](https://docs.craftcms.com/api/v3/craft-services-assets.html#method-findfolder) method might be useful but [ensureFolderByFullPathAndVolume](https://docs.craftcms.com/api/v3/craft-services-assets.html#method-ensurefolderbyfullpathandvolume) is probably more precise.
  
  For example:
  
  ```
  {{ hiddenInput( 'secret_folder_id', 
      craft.app.assets.ensureFolderByFullPathAndVolume($volumePath, $assetVolume) ) }}
  
  ```
  
  > **Comments:**
  > **username_0**: Sorry, my request upon re-reading it might be vague. I have the folderId, the question is how tell the frontend form to make sure the asset gets uploaded specifically to that subfolder. I want something like {{ hiddenInput('folderId':44) }} but that does not work and the asset always just uploads to the parent volume, not the subfolder  
  > **username_1**: Ok, I *think* I know what you mean. You could try changing the properties of the asset field, checking "Restrict assets to a single folder" and specifying the path to the subfolder you'd like things to save to.  
  
  ---
  
  