mercredi 5 décembre 2018

Dokku persistent storage with laravel gives 403 Forbidden when accessing from web

I'm creating an application with Laravel & uploaded to a VPS with Dokku. Everything is working fine. The application store images to the storage directory using local "disk" driver and have used native methods as available in Laravel. Due to the volatile nature of containers, I needed to set up persistent storage and followed this: http://dokku.viewdocs.io/dokku~v0.13.1/advanced-usage/persistent-storage/

I'm using this code below in Laravel to upload users' uploaded images. It's kind of a CMS application, so saving in the similar filename as we get from the user (Something similar to WordPress). Here is the code:

public function saveToDisk( UploadedFile $file ){

    $storage = Storage::disk();
    $storageDir = static::storageDir();

    $extention = $file->getClientOriginalExtension();

    $extensionLength = mb_strlen( $extention );
    $filename = substr( $file->getClientOriginalName(), 0, -( $extensionLength > 0 ? $extensionLength + 1 : 0 ) );

    $try = 0;
    $maxTry = 5;
    $suffix = '';

    while( $try < $maxTry ){

        $expectedFilename = "$filename$suffix.$extention";
        $expectedPath = $storageDir['dir'] . '/' . $expectedFilename;

        if( !$storage->exists( $expectedPath ) ){
            $file->storePubliclyAs( $storageDir['dir'], $expectedFilename );
            $storageDir['title'] = "$filename$suffix";
            $storageDir['filename'] = $expectedFilename;
            return $storageDir;
        }

        $try++;
        $suffix = "-$try";
    }

    return false;

}


public static function storageDir(){

    $today = Carbon::today();
    $baseDir = 'public/uploads';

    return [
        'dir' => "$baseDir/$today->year/$today->month",
        'base' => $baseDir,
        'year' => $today->year,
        'month' => $today->month,
    ];
}

File is getting uploaded nicely but the main problem is with permission. As suggested in the link above, I've already changed the permission for the upload directory. But after uploading the file the file has:

-rw-r--r-- 1 herokuishuser herokuishuser 152434 Dec  5 13:22 Ferry_Font5.jpg

And it fives 403 Forbidden when I try to access the file in browser.

But when I changed it with chmod 777 it is accssible from the browser.

Please help me to solve this, if you need any more info just ask. Also, please explain if I'm doing anything wrong.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2EeDwI3
via IFTTT

Aucun commentaire:

Enregistrer un commentaire