I am using Amazon s3 but here i am facing two problems
1.I can't directly upload files to amazon server when i submit form.I mean i have to upload images to an upload folder
on my PHP server and from there i have to retrieve and upload them to s3 server
. Is there a way to upload images directly to s3
when we click on submit?
2.If i pass 'public'
in s3 put object
then i can access or view files, but if i make it public every one can view files. But i need to protect all files and view only to the authenticated user. Can any one suggest me how to fix this issue?
try {
$s3 = \Storage::disk('s3');
$s3->put($strFileName, file_get_contents($img_path.$strFileName), 'public');
} catch (Aws\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n"+$e;
}
Before asking questions i have read many answers from stackoverflow but it didnt helped me to fix my issue. Thanks.
For you first question, it can be directly upload images to AWS S3.
$s3 = \Storage::disk('s3')->getDriver();
$s3->put($filePath, file_get_contents($file), array('ContentDisposition' => 'attachment; filename=' . $file_name . '', 'ACL' => 'public-read'));
You are supposed to specify your file path and the file you get from the form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With