首页 > 解决方案 > Change name of uploading file into s3

问题描述

I use the below code to store an image to my S3 disk. But using this code i get a random name i.e filename to the image that I'm uploading. So how can i set the filename of $request->renter_proof while uploading? Someone please help.

$storagePath = Storage::disk('s3')
    ->put('/company/'.Auth::user()->company.'/renter-proof/',
          $request->renter_proof,
          'public');

I want the name of the file to be :

$imageName = 'Tag '.$request->input('stock_on_rent').'.'.$request->renter_proof->getClientOriginalExtension();

标签: phplaravel-5amazon-s3

解决方案


解决方案是使用putFileAs()

我使用了以下代码:

$path = "/company/".Auth::user()->company."/renter-proof";        
$imageName = 'Tag '.$request->input('stock_on_rent').'.'.$request->renter_proof->getClientOriginalExtension();    
$storagePath = Storage::disk('s3')->putFileAs($path,$request->renter_proof,$imageName ,'public');

推荐阅读