Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

demonz's avatar

uploading image in s3 return 0 path

hello , when I set visibility to public for s3 in filesystem and i remove the block access in the bucket, when i store the image it returns 0 and when i remove public visibility and add the block access again it store the path correctly why !!

 'cv' => $validatedData['cv']
                ->storeAs('Learners/'.$validatedData['first_name'].' '.$validatedData['last_name'].' '.$validatedData['cpr'], $cv_fileName, 's3'),
0 likes
13 replies
LaryAI's avatar
Level 58

It's possible that the issue is related to permissions. When you set the visibility to public, you're allowing anyone to access the file. However, you also need to make sure that the IAM user or role that you're using to upload the file has the necessary permissions to write to the bucket.

You can check the IAM policies associated with your user or role to make sure that they have the necessary permissions. You can also try using the AWS CLI to upload the file and see if you get any error messages that might give you more information about the issue.

Here's an example of how you can upload a file to S3 using the AWS CLI:

aws s3 cp /path/to/local/file s3://bucket-name/path/to/remote/file --acl public-read

This command will upload the file to the specified S3 bucket and set the ACL to public-read, which should allow anyone to access the file. If you get an error message, it might give you more information about the issue.

If you're still having trouble, you might want to check the S3 access logs to see if there are any errors or issues with the requests that are being made. You can also try reaching out to AWS support for assistance.

demonz's avatar

it return false , and when i remove 's3' it return the path

sirhxalot's avatar

Hi Demonz

May you have an issue with your filename - Its possible that its not the case but try to normalize the path:

Unprintable and invalid unicode characters will automatically be removed from file paths. Therefore, you may wish to sanitize your file paths before passing them to Laravel's file storage methods. File paths are normalized using the League\Flysystem\WhitespacePathNormalizer::normalizePath method.

Did you set the file visibility to public? https://laravel.com/docs/10.x/filesystem#file-visibility

demonz's avatar

@sirhxalot yeah and now i removed 'visibility' => 'public', and it seems it cause the issue , but the block access is still unchecked in aws console , but now how do i show the images ? or make a download button in laravel breeze

sirhxalot's avatar

@demonz What do you want to achive? Public means that everyone can download or view the file. If you want to make a restriction lets say only user xy can get the file than you will need to add a midleware or at least a controller action which handles that for you.

demonz's avatar

@sirhxalot i have CPR images shouldn't be public , I have Course image which should be public because i want to display them to the user , so i create a bucket upload-file in amazon s3 , and i unchecked block access , but the problem is that the url is showing like this when I open it inside the console https://file-upload.me-south-1.amazonaws.com/Learners/test12yy%20test123%20440/test12yy_test123_CPR.jpg?response-content-disposition=inline&X-Amz-Security-Token=IQoJb3..... which means https://file-upload.me-south-1.amazonaws.com/Learners/test12yy%20test123%20440/test12yy_test123_CPR.jpg , wouldn't work because it needs this response and it will show error access denied "This XML file does not appear to have any style information associated with it. The document tree is shown below."

demonz's avatar

@sirhxalot i just wanna do one thing now , store them with public visibility , for some reasons visibility doesn't change even if use setVisibility or storePubliclyAs , i created the bucket and i remove the block access , and i add 'visibility' => 'public' , but it doesn't store

demonz's avatar

@sirhxalot i am sure amazon played with setting cause i was following someone video and it doesn't store in their s3 , this got me tired bro

sirhxalot's avatar

@demonz I dont think so I am using multiple S3's a few of them are public some not and I didn't had to change my buckets. How does your configuration looks like anyway did you try to set the visibility to public like so:

's3' => [
            'driver' => 's3',
            'key' => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => ('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'visibility' => 'public',
]

Please or to participate in this conversation.