mercredi 14 février 2018

Laravel S3 image upload creates a folder with the filename automatically

I'm using Laravel 5.4.*. I've this simple code in a helper file to upload images/gif in S3 bucket under a folder named say "instant_gifs/". The code is below:

if ( !function_exists('uploadFile') ) {

function uploadFile($fileContent, $fileName, $size='full', $disk='s3')
{
    $rv = '';
    if( empty($fileContent) ) {
        return $rv;
    }

    if($size == 'full') {
        dump($fileName);

        $path = Storage::disk($disk)->put(
                    $fileName,
                    $fileContent,
                    'public'
                );
    }

    if ( $path ) {
        $rv = $fileName;
    }

    return $rv;
}

}

From the controller, I'm calling the helper method as below:

$file = $request->gif;
$file_name = 'instant_gifs/' . $user_id . '_' . time() . '_' . $file->getClientOriginalName();
$result = uploadFile($file, $file_name);

In the the $fileName parameter of the helper method, I'm providing the fileName as for example in this format:

"instant_gifs/83_1518596022_giphy.gif"

but after the upload, I see that the file gets stored under this folder

"vvstorage/instant_gifs/83_1518596022_giphy.gif/CRm1o1YEcvX3fAulDeDfwT7DIMCxOKG8WFGcA3lB.gif"

with a random file name

CRm1o1YEcvX3fAulDeDfwT7DIMCxOKG8WFGcA3lB.gif

Whereas, according to the code, it should get stored in this path:

"vvstorage/instant_gifs/83_1518596022_giphy.gif"

Doesn't get any explanation why this is happening. Any clue will be appreciated.

BucketName = vvstorage
Folder I'm mimicking = instant_gifs



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire