Bilal Arshad
Bilal Arshad

Reputation: 571

S3 bucket is not allowing to upload files in laravel

We are trying to upload file on amazone s3 bucket but it is not working . File delete and read work fine . but upload not working.

 $url = Storage::disk('s3')->url('bulk_pdf_consignments/manifest' . $this->manifest_id . '_.pdf', fopen($bulk_pdf, 'r+'));

I think we need add policy but don't know about it.

Upvotes: 0

Views: 1603

Answers (1)

Your upload code has to be something like this:

Storage::disk('s3')->put($pathToSaveOn, file_get_contents($request->file->getRealPath()));

After upload you can get s3 url this way:

$url = Storage::disk('s3')->temporaryUrl($imagePath,now()->addMinutes(10));

Note: This code is to upload private file, so, you need to generate temporary url To upload file publicly you need to pass 3rd argument public

Storage::disk('s3')->put($pathToSaveOn, file_get_contents($request->file->getRealPath()), 'public');

Upvotes: 4

Related Questions