I’ve added
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
AWS_BUCKET
in Heroku and the according value to Heroku Config Vars.
Then, I uploaded image to ‘/images’ folder on s3.
$path = $request->file('image')->store('/images', 's3');
After that, Heroku server showed the following error:
server error 500 title
server error 500 specific
Is there anyone can help me explain what’s going on? Thanks a lots. I’m trying figure out…
UPDATE:
Here is my create.blade.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> </head> <body> <form action="/" method="POST" enctype="multipart/form-data"> @csrf <input type="file" name="image" id="image"> <button type="submit">Upload File</button> </form> </body> </html>
I took @Rwd’s advice, type dd($request->hasFile('image'));
in controller
In localhost, it showed true
In Heroku Server, it showed false
SOLUTION
@bhucho adviced to change form action
from "/"
to " {{url('/') }} "
And it returned true
now, I can upload image to s3.
Thanks everyone’s help!
Advertisement
Answer
Change your <form action="/" method="POST" enctype="multipart/form-data">
to <form action="{{ url('/') }}" method="POST" enctype="multipart/form-data">
In the development server environment, it will run fine.See Mozilla Docs for The action attribute of form tag
However, deploying it to anywhere else but the root website will cause the action URL to become invalid. For instance, if it were deployed to https://example.com/deployed_app, then the actual action URL that the form will call is https://example.com/Home/Upload, which is invalid.
So if you use {{ url() }}
it will append the url mentioned in APP_URL of .env file.