degeta10's avatar

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();
0 likes
3 replies
degeta10's avatar

Yea thanks.... i did try PutFileAs() ... and i was trying old documentation XD. And it didnt work.... It works now.. The solution is:

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

@Cronix can u tell me how to find the uploaded file?

     $path = "/company/".Auth::user()->company."/renter-proof/";
    $file= $stock->renter_proof;  
    $filename = Storage::disk('s3')->get($path.$file);
    File::delete($filename);

I used the above code but it doesn't work. Can u please help?

Please or to participate in this conversation.