15

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 Exception(Craft::t('Paths not available for non-local asset sources')); } $sourcePath = $source->settings['path']; $folderPath = $asset->getFolder()->...


9

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 = { fileId: 100 }; $.post('/actions/assets/deleteFile', data, function(response) { // ... }); }); Craft 3: $('#delete-file').click(function() { ...


9

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 = Yii::getAlias($volumePath) . $folderPath . $asset->filename;


6

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 example assumes you've set a field photoId on your asset source: $fileId = $response->getDataItem('fileId'); $asset = craft()->assets->getFileById($fileId);...


5

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()->assets->getRootFolderBySourceId($iAssetSourceId)->id; $sTempFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $sFilename; $sFileContents = ...


5

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.request.getSegment(4) - 1 %} Also, probably a good idea to include the section param when fetching the entry, in case you have another entry in another section ...


5

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 get custom fields (of course) and revisions and you can use Entry Types to display them in the various formats that you require.


5

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 with the relatedTo parameter to be more spezific on that relation. But you should be fine using the element property or the short syntax relatedTo(element), if ...


4

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 this with a Route somehow?


3

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}/{slug} If there are any gotchas on this let me know and I'll edit this answer to include them.


3

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 Variable class that accepts the AssetFileModel object, grabs the image, stamps it with the watermark and saves it somewhere else, returning the URL to that ...


3

Found it! The specific field can be targeted like this: $criteria->childField = 'myFieldHandle';


2

No, currently it will allow all file types and does not take the extraAllowedFileExtensions config setting into account.


2

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 'forceDownload' => true as one of the key => value pairs to force it to download to the browser. Instead of hardcoding the the path to your public assets folder, you ...


2

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 (Here the images directory is under public directory) In Azure portal, Add the following App settings in Application setting of your App service: key: ...


2

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 entry of Products.


2

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 transforms later, you might have to do some magic / use different variables.


2

It's not going to work with this particular plugin: // Require an instance of `AssetFileModel` if (! $asset instanceof AssetFileModel) { // Die quietly. return false; } It specifically checks the parameter that you pass in, and expects it to be an AssetFileModel. It wouldn't be too hard to modify the ...


2

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" %} <ul> {% for icon in block.icon %} <li>{{ icon }} {% endfor %} </ul> {% ...


2

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: $volume = $this->getVolume(); $assetFilePath = $volume instanceof LocalVolumeInterface ? FileHelper::normalizePath($volume->getRootPath() . ...


1

Cant you just do as described in the craft docs? -> https://craftcms.com/docs/assets-fields#uploading-files-from-front-end-entry-forms


1

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.parent.loop.parent.loop.index }}


1

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

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 has a getChildren method you could loop through to get all of the subfolders for the given folder. Depending on how numerous your file/folder structure is, ...


1

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 you're working with when you're using craft.assets). What you could do is to create a simple, custom plugin exposing the AssetsTransformsService to Twig by ...


1

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 and perhaps more in line with your specific question, have a look at this related thread: Best way to access getPrev and getNext asset fields


1

Turns out this was because several tables were missing the MySQL auto-increment flag for their id integer primary keys.


1

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 access sourceUrl the same as the others: {{ entry.assetHandle.first().sourceUrl }} They definitely aren't attributes on Craft's AssetSourceModel.


1

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 had checked to make sure everything was good but I guess not. Thanks for the help @BradBell.


1

Headers passed back from S3 have to be set either on object upload or copy. You would have to use S3::copyObject() to copy the object to itself and set the appropriate headers (mentioned here: https://stackoverflow.com/a/25933113/2040791) Alternatively, you can use the method mentioned in the same thread and force a download using HTML5, but that won't work ...


Only top voted, non community-wiki answers of a minimum length are eligible