I have been able to successfully save the files on Amazon s3 bucket but I am having issues when I try to download files from the s3 bucket. I get the below error when I click the download button.
AssignmentController
public function store(Request $request)
{
$this->validate($request,[
'name' => 'required',
'file' => 'required|max:2048',
'task_id' => 'required'
]);
$assignment = new Assignment;
if($request->hasFile('file')){
$file = $request['file'];
$ext = $file->getClientOriginalExtension();
$filename = uniqid().'.'.$ext;
$filePath = 'assignments/' . $filename;
Storage::disk('s3')->put($filePath, file_get_contents($file));
$assignment->file = $filename;
$assignment->save();
}
DownloadController
public function assignmentdownload($id){
$file = Assignment::find($id);
# Filename
$filename = $file->file;
$pathToFile = Storage::disk('s3')->url($filename);
return Storage::download($pathToFile, $filename);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire