15
votes
Accepted
How to get absolute path to asset file?
You can get the rest of the path from your asset's source and folder, I think something like this should do it:
$source = $asset->getSource();
if ($source->type != 'Local')
{
throw new ...
11
votes
How to get absolute path to asset file?
Update for Craft 3:
To get the same output as Mike's path above, you can use:
$volumePath = $asset->getVolume()->settings['path'];
$folderPath = $asset->getFolder()->path;
$assetFilePath ...
9
votes
Accepted
How do you delete assets from a frontend form?
You can create a POST request via Ajax to the assets/deleteFile (Craft 2) / assets/delete-asset (Craft 3) controller action:
Craft 2:
$('#delete-file').click(function() {
var data = {
...
6
votes
Accepted
How to set a field of an asset from within a plugin
To save a custom field value on an Asset, you'll first need to pull the actual AssetFileModel, set the custom attribute on the Asset's ContentModel, and finally re-save the Asset.
The following ...
5
votes
Accepted
Is it possible to create a new asset from an image URL?
Download the image into a temp file, then upload it as an asset. You can find $iAssetSourceId by looking at the URL when editing an asset source
$iAssetSourceId = 4;
$iAssetFolderId = (int)craft()-&...
5
votes
Accepted
Better way to find a specific asset?
That’s definitely the way to do it!
I would set the URL segments to their own variables, to clean it up a little bit.
{% set entrySlug = craft.request.getSegment(2) %}
{% set imageOffset = craft....
5
votes
Accepted
Management of large number of downloadable PDFs
I'm not familiar with Docman (or Joomla for that matter), but I think Craft is perfectly capable of doing what you're describing.
Your strategy of creating an entry per PDF seems reasonable. Entries ...
5
votes
Accepted
How do I display a list of assets with the entries they are related to?
You probably have to query a new ElementCriteriaModel for each asset in your loop and use the relatedTo parameter to filter the relevant "content" entries.
You could use the targetElement property ...
4
votes
Is there a 'slug' for assets?
Could you add your own field to use as a slug?
When you edit an Asset Source in Settings you get the Field Layout tab same as you do for Entries. You could maybe add something there and then combine ...
4
votes
How to get absolute path to asset file?
See Asset::getImageTransformSourcePath() for how Craft CMS resolves the real local path. (https://github.com/craftcms/cms/blob/develop/src/elements/Asset.php#L1200)
Should look something like this:
$...
3
votes
Accepted
What is the proper way to set an asset's upload location using the slugs/ structure path of the entry it is selected from?
To include the handle of the slug, and the path within the structure based on the entry uploaded from in the upload location field I've found the following to work:
{section.handle}/{parent.uri}/{...
3
votes
Accepted
Is it possible to hook into image transforms?
Currently it’s not possible to hook into Craft’s own thumbnail/transform generation logic. Your best bet would be to write a plugin that independently adds the watermark.
You could give the plugin a ...
3
votes
Accepted
How can I get a related Asset of a specific field?
Found it! The specific field can be targeted like this:
$criteria->childField = 'myFieldHandle';
2
votes
Accepted
File input attachment format for Contact Form plugin
No, currently it will allow all file types and does not take the extraAllowedFileExtensions config setting into account.
2
votes
Accepted
Send an asset from a plugin controller
There might be a way to do this with CBaseController::renderFile(), but I'd just use craft()->request->sendFile().
The 3rd parameter is an optional $options array and you can pass a '...
2
votes
Accepted
File upload error in MS Azure after custom domain was pointed to Azure server
MS support team helped to resolve the issue. I will post the steps to be followed.
In your CMS Admin, Under Assets source ->
File system path: images/
URL: http://example.azurewebsites.net/images
(...
2
votes
What is the proper way to set an asset's upload location using the slugs/ structure path of the entry it is selected from?
Assuming your Structure section is named Products with a handle of products you could try this:
{section.handle}/{parent.uri}/{slug}
Or you would have to restructure your entries to have a parent ...
2
votes
Accepted
How can I base64-encode an Image Transform?
Try this:
{% set image = assetField.first().setTransform({width: 40}) %}
That should return an AssetFileModel, allowing you to do {{ image64(image) }}
If you need to reuse the image with other ...
2
votes
How can I base64-encode an Image Transform?
It's not going to work with this particular plugin:
// Require an instance of `AssetFileModel`
if (! $asset instanceof AssetFileModel)
{
// Die quietly.
...
2
votes
Accepted
Object of class Craft\ElementCriteriaModel could not be converted to string
You'll want to use block.icon.first() if you just want the first Asset, or you could loop through all Assets:
{% for block in entry.visitorContentBuilder %}
{% if block.type == "listItemWithIcon"...
1
vote
Accepted
Search for assets containing a custom field
Caveat: This is totally untested, and could be nonsense. I'm sure you'll let me know. It assumes that the Craft element query methods can be used here.
If you have a 'lang' value, add a where to your ...
1
vote
Uploading an Asset from a custom CP-Tab in Craft 2.x
Cant you just do as described in the craft docs? -> https://craftcms.com/docs/assets-fields#uploading-files-from-front-end-entry-forms
1
vote
Error when outputting assets from a field within a Neo field
The issue here was not to do with NEO or how to access them, it was the loop index call to the parent not getting the correct context.
{{ loop.parent.index }} was the issue. It needed to be {{ loop....
1
vote
Error when outputting assets from a field within a Neo field
You'll need to reference the field handle within asset.
For instance > {{ asset.imageHandle.getUrl('square') }}.
I'm guessing you aren't seeing {{ asset.title }} either?
1
vote
List subfolders of a specific asset folder
Not a complete answer, but in your example image if going to be an instance of AssetFileModel.
AssetFileModel has a getFolder method that returns an instance of AssetFolderModel.
AssetFolderModel ...
1
vote
Accepted
How to retrieve the mode of an image transformation from its name?
Not possible out of the box, unfortunately. Asset transforms can be pulled by using the AssetsTransformService, but Craft doesn't expose that service to Twig (unlike the AssetsService, which is what ...
1
vote
Next/Previous Asset or Image within Entry
Given that your assets are within an entry, it seems that a gallery browsing mechanism may fit well. I'd suggest a javascript framework such as Fancybox: http://fancyapps.com/fancybox/
Alternatively ...
1
vote
CBdException: Column 'id' cannot be null
Turns out this was because several tables were missing the MySQL auto-increment flag for their id integer primary keys.
1
vote
Accepted
Accessing the attributes of an Asset field
I'm assuming that Alt Text (handle altText), Source Name (handle sourceName) and Source URL (handle sourceUrl are all plain text custom fields you've created on your Assets.
If so, you'd be able to ...
1
vote
Accepted
Image asset URI returning null
Through Pixel and Tonic's support email, I figured out what the issue was. It turns out one of my entries didn't have a thumbnail and that was why the image was null. Stupid user error! I thought I ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
assetfilemodel × 28assets × 24
plugin-development × 8
image-transforms × 3
templating × 2
image × 2
loop × 2
entries × 1
matrix × 1
database × 1
search × 1
relations × 1
entry × 1
form × 1
elementcriteriamodel × 1
filter × 1
controller × 1
variable × 1
craft-pro × 1
plugin-contactform × 1
s3 × 1
hook × 1
index × 1
twigextension × 1
plugin-neo × 1