<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>

CC BY-SA 4.0
2021-04-28T23:12:22.377Z
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
AbbeyDesign
CC BY-SA 4.0
2021-04-29T08:26:52.963Z
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.
Wallace
CC BY-SA 4.0
2021-04-26T07:41:10.067Z
2021-04-26T07:41:10.067Z
Wallace
<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>


<frontend-form>
Specify FolderId When Uploading a File on the Frontend
# 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

 {{ 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,
          }) }}
    Upload

**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 method might be useful but 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.  

---

