Hot answers tagged

47

413 errors occur when the request body is larger than the server is configured to allow. Here’s how you can fix it, depending on your web server: Apache: Set the LimitRequestBody directive in either your httpd.conf file or a local .htaccess file. (https://stackoverflow.com/a/3719358/1688568) Nginx: Set the client_max_body_size directive in nginx.conf (http:...


38

You can do this using image transforms. There are a couple things you’re going to need to consider though: Not every image will necessarily be high-res (e.g. a computer screenshot taken on a non-retina screen) You probably don’t want to output images that are larger than their original size For #1, we need some way of identifying images that are 1X vs. 2X....


21

That’s what getUrl() returns if the transform hasn’t been generated yet. When the browser requests that URL, Craft will generate the transform, and respond with a 302 redirect to the actual image URL. Update: As of Craft 2.2, even if the transform generation URL doesn’t get directly requested (e.g. if it’s a social media image, or a srcset size that doesn’t ...


19

The easiest way I imagine would be to Create a local folder Download all the files into the folder (outside of Assets - via Transmit or similar) Change your source settings from S3 to Local with correct paths And you're done. Whoa, that was easy :)


18

I can't actually reproduce your problem but here's a couple of things to check and try: Clear your browsers cache! Did you re-upload through Assets with the same filename and click replace? Purge all the caches via the Clear Caches button on the settings page Update Asset Indexes on that same page Failing those, manually delete the contents of the /craft/...


18

OK, figured it out (or at least it works, so correct me if a better way is available): This method assumes logged in frontend users, not sure if it's possible for guests, have not tested that. Might give permission errors. Let's say, we have a section message with id 2, containing an asset field called photos. This is the field in which we want to save all ...


17

Allright, I'll bite. First, I'll get the cost argument out of the way, then I'll cover each type with their specifics. Costs Amazon S3: USD 0.03 per GB (up to 1TB, where the price drops as you store more and more data) Rackspace: USD 0.12 per GB (up to 1TB, where the price drops) Google Cloud Storage: USD 0.026 per GB (No price reduction for large amounts) ...


17

If you simply go into your craft_assettransformindex table and empty it, that should trigger brand new transformations for everything.


17

So after looking through other craft websites to see how they where able to get images to work I discovered what I did wrong when setting up the asset source. The thing is though that the craft documentation is not very helpful in this regard, also there are no errors or helpful output to indicate that my configuration might be the issue.


16

I did this recently with my Ad Wizard plugin... There are several different parts which need to be brought together to make it work: In your Record file, add this to defineRelations: 'asset' => array(static::BELONGS_TO, 'AssetFileRecord') In your Model file, add this to defineAttributes: 'assetId' => AttributeType::Number Whichever template is ...


16

Before you can allow a user to manage their profile photo in your front-end profile edit form, be sure to update your form tag with the enctype="multipart/form-data" parameter: <form method="post" enctype="multipart/form-data"> You can access a users profile photo using the currentUser global and fallback to a different image like so: {% if ...


16

I bet this trips up a lot of people at first, but your asset field will return a ElementCriteriaModel, not your image. To get to image, you need to fetch it. If your field has only one image, you will do something like this: {# Fetches the first image #} {% set image = entry.featureImage.first() %} {# It's good to check if you actually have an image before ...


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()->...


15

This isn't really related to Craft specifically, but to allow a user to link to an asset, you will need to enable the feature in the redactor configuration file. For example, within this file: /craft/config/redactor/Standard.json You will see something like this: { "buttons": [ "html", "formatting", "bold", "italic", ... You will ...


14

Craft itself, limits the filesize only in the maxUploadFileSize. Default: 16MB However Craft gets limited by: PHP: Has a few values which might cause the problem: memory_limit max_input_time upload_max_filesize post_max_size AmazonS3: If not limited by a policy value, the default is 5GB. User: Sometimes it can be just a Browser issue causing the problem....


14

Check out my plugin Inlin, I made it exactly for this. :)


14

Yes, you can access a number of properties on assets. You can get the "file group" (whether it's a document, image, video etc) using: {{ asset[0].kind }} More specifically, you can access the file extension using: {{ asset[0].extension }} Full list in the documentation at: http://buildwithcraft.com/docs/templating/assetfilemodel


13

The data in Craft is handled mostly by Models (and arrays of Models). Before pulling actual information, you define your criteria in an ElementCriteriaModel using generic parameters and parameters specific to what you are trying to get (entries, assets, etc.). You then use one of the ElementCriteriaModel's functions to pull the actual data. You will get ...


13

I had this same issue and resolved it (at the suggestion of Craft CMS support) by enabling ImageMagick in the php.ini and restarting MAMP PRO. Per the MAMP PRO 3.0 user guide: The ImageMagick PHP module is included by default, but you must enable it inside the php.ini template file. Remove the ‘;’ from the following line. ;extension=imagick.so


13

You need to allow to list bucket location. Also, I'm not confident if you'd be able to upload and delete objects from the bucket with that policy. I'd go with: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListAllMyBuckets" ], "Resource": "*" }, { "Effect": "...


12

There are a few regions that support only S3's v4 of signing requests without the possibility of falling back to v2. The S3 library that Craft 2 uses only supports S3 v2. Check this table for reference - if it says "Version 4 only" in the last column then that region can't be used in Craft 2. We're not switching out that library in Craft 2.x, but it won't ...


12

I finally figured out how to upload an asset, however I still don't understand why the insertFileByLocalPath has been removed. /** * @param UploadedFile $uploadedFile * @param int $folderId * @return Asset * @throws BadRequestHttpException * @throws UploadFailedException */ protected static function uploadNewAsset(UploadedFile $uploadedFile, $folderId)...


11

It's almost always an environmental limitation. The most common culprits are: 1) PHP's memory_limit setting: http://us3.php.net/manual/en/ini.core.php#ini.memory-limit 2) PHP's post_max_size: http://us3.php.net/manual/en/ini.core.php#ini.post-max-size 3) PHP's upload_max_filesize http://us3.php.net/manual/en/ini.core.php#ini.upload-max-filesize These ...


11

This actually is possible if you navigate to the folder or sub folder where you are trying to add the asset and then upload a file with the exact same file name. Craft will ask you if you want to replace the existing file or upload another version with an appended name (for example "my-file-1.txt")


11

I think you're confusing the "Width" setting to mean "Max Width", which it doesn’t. The image will get sized to match your transform's Width setting, regardless of whether it's bigger or smaller than that width beforehand. If you want to conditionally apply the transform, only if it's larger than the transform's width, you can do this: {% if asset.width &...


11

This should do it: {% set bytes = asset.size %} {% set kiloBytes = (bytes / 1024)|round(2) %} {% set megaBytes = (kiloBytes / 1024)|round(2) %} bytes = {{ bytes }} kiloBytes = {{ kiloBytes }} megaBytes = {{ megaBytes }} You can look at Twig's number_format filter if you want to get fancy with how to display the numbers.


11

An Asset field – like all relational fields, including Entries, Categories etc – always return an array-like object which is an instance of a class called ElementCriteriaModel. To output the actual file data, this means you have to loop on the field, e.g.: {% for asset in entry.wireframeImages %} <img src="{{ asset.getUrl() }}" /> {% endfor %} ...


10

Yes you can do that with an Entry Form in your template. Have a look at the assets fields article in the docs, there is a small section about uploading files from front-end forms.


10

If you want a user to be able to upload a profile photo from the front-end, the you should be able to add enctype="multipart/form-data" to your form that saves your user and have a file input called 'userPhoto'. <input type="file" name="userPhoto" id="image-upload" /> If you want to delete a user's existing profile photo, then add a hidden input ...


10

Yes. getWidth will give you an image's width: {% set originalWidth = image.getWidth(false) %}. You want to apply the transform if desiredWidth is less than originalWidth. I would write a twig macro: {% macro transform(image, desiredWidth) %} {% set originalWidth = image.getWidth(false) %} {% if desiredWidth < originalWidth %} {{ image.getUrl({...


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