1

Is it possible in a front end entry form to pass the URL of a file to an assets field and have it upload that way? Specifically, I'm trying to move an image from one assets field & upload folder to another in an edit entry form.

  • Just to clarify: are you moving an already uploaded file (has an asset id) to another folder? – Fred Carlsen Jan 7 '15 at 16:28
  • Yes, that's exactly what I'm trying to do. – Jacob Russell Jan 7 '15 at 17:29
  • Is there two Assets fields, each specified to upload to different folders? If so, you can just remove the asset id from one field and add it to the other. Also have a look at the actionMoveFile in AssetsController. You might need to make a simple plugin. – Fred Carlsen Jan 8 '15 at 12:46
  • Do you want to move the file (so the file no longer exists in the original location), or do you want it to be copied to the new location? – Brandon Kelly Jan 14 '15 at 14:31
  • Either option would be fine with me. What's important is that the assets field in the new channel point to the file, whether the field in the original channel still points to it doesn't matter that much. – Jacob Russell Jan 14 '15 at 14:40
2

It’s not currently possible to upload assets via URL, but if we’re only talking about images that are already uploaded into Craft, you could have them selected by their existing asset IDs, rather than URLs, and it would work.

First, go into your Assets field settings and check the “Restrict uploads to a single folder” checkbox.

Then in your entry form, write a UI for selecting an existing asset. Something like this:

<ul class="asset-selector">
    {% for image in craft.assets.source('images') %}
        <li>
            <label>
                <input type="radio" name="fields[myAssetsField][]" value="{{ image.id }}">
                {% do image.setTransform({ width: 100, height: 100 }) -%}
                <img src="{{ image.url }}" width="100" height="100" alt="{{ image.title }}">
            </label>
        </li>
    {% endfor %}
</ul>
|improve this answer|||||
  • Were you nearby, I would hug you in a manly fashion. 'Cause your smart. – Jacob Russell Jan 14 '15 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.