Chapters
40 Chapters
|
4:39:58
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
35.
S3 Asset Paths
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial is built on Symfony 4 but works great in Symfony 5!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"aws/aws-sdk-php": "^3.87", // 3.87.10
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.1
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.1
"knplabs/knp-paginator-bundle": "^2.7", // v2.8.0
"knplabs/knp-time-bundle": "^1.8", // 1.9.0
"league/flysystem-aws-s3-v3": "^1.0", // 1.0.22
"league/flysystem-cached-adapter": "^1.0", // 1.0.9
"liip/imagine-bundle": "^2.1", // 2.1.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.1.0
"oneup/flysystem-bundle": "^3.0", // 3.0.3
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.2.3
"symfony/console": "^4.0", // v4.2.3
"symfony/flex": "^1.9", // v1.21.6
"symfony/form": "^4.0", // v4.2.3
"symfony/framework-bundle": "^4.0", // v4.2.3
"symfony/property-access": "4.2.*", // v4.2.3
"symfony/property-info": "4.2.*", // v4.2.3
"symfony/security-bundle": "^4.0", // v4.2.3
"symfony/serializer": "4.2.*", // v4.2.3
"symfony/twig-bundle": "^4.0", // v4.2.3
"symfony/validator": "^4.0", // v4.2.3
"symfony/web-server-bundle": "^4.0", // v4.2.3
"symfony/yaml": "^4.0", // v4.2.3
"twig/extensions": "^1.5" // v1.5.4
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.1.0
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.2.3
"symfony/dotenv": "^4.0", // v4.2.3
"symfony/maker-bundle": "^1.0", // v1.11.3
"symfony/monolog-bundle": "^3.0", // v3.3.1
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.2.3
"symfony/stopwatch": "4.2.*", // v4.2.3
"symfony/var-dumper": "^3.3|^4.0", // v4.2.3
"symfony/web-profiler-bundle": "4.2.*" // v4.2.3
}
}
14 Comments
Even after updating the uploads_base_url parameter, I can't see the images because AWS S3 actually asks for an URL using the bucket name as a subdomain.
For anyone encountering this too, your parameter should look like:
<br />uploads_base_url: 'https://%env(AWS_S3_ACCESS_BUCKET)%.s3.amazonaws.com'<br />Yep. That's correct! :)
Hey AymDev,
Thank you for sharing this tip with others!
Cheers!
Hallo, I dot this error during reload page,
Block public access (bucket settings)
In bucket I enable just
Block public and cross-account access to buckets and objects through any public bucket or access point policies
and
Block public access to buckets and objects granted through new public bucket or access point policies
I tried disable all ow those, but it does not healp, could it be the other reason?
Hey Jurij,
I personally haven't gotten this error myself, so difficult to say. Try to google this specific error, I bet you will find much more useful advice than I could give you in this case. E.g. the first StackOverflow question I googled for this error you mentioned: https://stackoverflow.com/questions/71080354/getting-the-bucket-does-not-allow-acls-error - please, take a look at the answers, I hope they help!
Cheers!
Hello ! :-)
I don't know why my imagine bundle is still not able to write in my S3 bucket ?
Everything else is working fine as a strictly followed the instructions.
Could that come from FlySystem v2 or any other difference on packages versions ?
I always used the latest versions for all packages used in that tutorial.
OK I think I found the problem !
Now, when creating (or editing) a bucket, there is an option called Object Ownership with which you can set ACLs disabled (which was recommended) or ACLs enabled.
Setting ACLs enabled fixed my problem, because it allows you to set the visibility of a bucket object when uploading it.
The object being now publicly visible, imagine bundle can load it AND save it back to S3 with the public visibility.
Hope I am not too wrong here :-D
Hey there,
Nice! You sorted it out by yourself. AWS access config it's always a pain. Basically, what you want is to make your images publicly visible, and the AWS account that upload files should have write permissions on your bucket
Cheers!
Hey Team,
I succeeded to use AWS S3 to store image and it's working fine on local with league/flysystem-bundle and liip/imagine-bundle. On Heroku (hobby dynos), the upload is ok but there is a problem on generate thumbnail.
Do you know what I have to check ?
Cheers.
Hey Stephane
Do you see any exceptions? If it's a thumbnail generation, probably there GD lib or Imagick misconfiguration... but without any exception message it's pretty hard to say something.
Cheers!
Hey @Vladimir,
Thank you for your reply. I have a 404 not found message for image.
https://snowtrick-app.herok...
I have added the GD lib in composer.json already.
Perhaps it is a problem with Nginx server ? Or a router problem ?
On local, when I paste the path of the image :
https://localhost:8000/media/cache/resolve/image_thumb_home_xl/snowtrick-image/default-snowboard-trick.webp
is transform on
https://s3-image-snowtrick....
But when I paste the path of image on Heroku app :
https://snowtrick-app.herok...
there is no automatic switch
Cheers.
Yeah probably it can be nginx issue, Probably you have nginx rule for static files which throws 404 on not found file instead of sending it to php. Can you show your nginx configuration on heroku app?
Cheers!
location / {
# try to serve file directly, fallback to rewrite
try_files $uri @rewriteapp;
}
location @rewriteapp {
# rewrite all to index.php
rewrite ^(.*)$ /index.php/$1 last;
}
location ~ ^/index\.php(/|$) {
try_files @heroku-fcgi @heroku-fcgi;
# ensure that /index.php isn't accessible directly, but only through a rewrite
internal;
}
location ~* \.(css|js|jpg|png|webp)$ {
access_log off;
add_header Cache-Control public;
add_header Pragma public;
add_header Vary Accept-Encoding;
expires 1M;
}
try to add
try_files $uri @rewriteapp;to thelocation ~* \.(css|js|jpg|png|webp)$ {blockThis should help, I think
"Houston: no signs of life"
Start the conversation!