This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Anand Patel
Anand Patel

With local storage its working perfect, when i switch to s3 storage, its throwing error when we upload csv file. from debugging i found that it is because of https://github.com/octobercms/library/blob/master/src/Database/Attach/File.php#L248

any possible solution for this?

shoguniphicus
shoguniphicus

What I did was hardcoding the path of where to save the local file from S3 and then return the path. So far it works, will need further testing to see if it has other problem. Haven't have enough time to look into making it fully dynamic.

What I did was, create another abstract class to use ImportModel and then specify a new class to use as import_file.

/**
     * Relations
     */
    public $attachOne = [
        'import_file' => ['Sho\Demo\Models\File']
    ];

And inside that new class, I overwrite the function getLocalPath() to,

public function getLocalPath()
    {
        if ($this->isLocalStorage()) {
            return $this->getLocalRootPath() . '/' . $this->getDiskPath();
        }
        else {
            //
            // @todo The CDN portion of this method is not complete.
            // Things to consider:
            // - Generating the temp [cache] file only once
            // - Cleaning up the temporary file somehow
            // - See media manager process as a reference
            //

            $storagePath = 'uploads/public/'.$this->getPartitionDirectory(). $this->disk_name;
            $localPath = $this->getLocalTempFilePath($this->file_name);

           //FileFacade is actually Illuminate\Support\Facades\File
            FileFacade::put($localPath, Storage::get($storagePath));
            return $localPath;
        }
    }

    protected function getLocalTempFilePath($fileName)
    {
        $fileName = md5($fileName.uniqid().microtime());

        $path = temp_path() . '/uploads';

        if (!FileFacade::isDirectory($path))
            FileFacade::makeDirectory($path, 0777, true, true);

        return $path.'/'.$fileName;
    }

Last updated

daftspunky
daftspunky

We need some solution to flag the file upload as local, since it doesn't need to be stored on a CDN. Can someone log an issue for this on the octobercms/october GitHub repo and we'll take a look at it.

jvanremoortere
jvanremoortere

Has anyone done this? Can't seem to find it...

daftspunky
daftspunky

This method has been completed as part of this commit. Code used:

    public function getLocalPath()
    {
        if ($this->isLocalStorage()) {
            return $this->getLocalRootPath() . '/' . $this->getDiskPath();
        }
        else {
            $itemSignature = md5($this->getPath()) . $this->getLastModified();

            $cachePath = $this->getLocalTempPath($itemSignature . '.' . $this->getExtension());

            if (!FileHelper::exists($cachePath)) {
                $this->copyStorageToLocal($this->getDiskPath(), $cachePath);
            }

            return $cachePath;
        }
    }

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.