Laravel 5.0:CSV created using fopen() and Upload on AWS S3 Bucket Using Storage

I am working on two things:

  1. Creating the CSV file using fopen() and inserting the data from mysql and Close the File.
  2. Now, need to upload that created file into AWS S3 bucket directly.

Now, I am able to created the CSV file, but unable to upload the file into AWS S3 bucket.

Laravel PHP Code:

public function download() {

$headers = array(
"Content-type" => "text/csv",
"Content-Disposition" => "attachment; filename=auditsystem.csv",
"Pragma" => "no-cache",
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Expires" => "0"
);
$columns = array(
'S.no',
'State Name',
'State Code'
);
$audit_params = DB::select(DB::raw("select * from table_state_codes"));
$callback = function() use ($audit_params, $columns) {
$file_name="auditsystem.csv";
$file = fopen('php://output', 'w+');
fputcsv($file, $columns);
foreach ($audit_params as $rowOrders) {
fputcsv($file, [
$rowOrders->id,
$rowOrders->state_name,
$rowOrders->state_code,
]);
}
fclose($file);
Storage::disk('s3')->put('uploads/' . $file_name, file_get_contents($file), 'public');

};

return response()->stream($callback, 200, $headers);
}

I am getting this error, Error Uploading on AWS S3 bucket

I am unable to Upload the File into AWS S3 bucket. Also, File format is kept w+, so that I can write as well as read also.

Please let me know where I am going wrong.Eagerly waiting for your opinions.

Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2JLYv9b
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time