GreyhoundIT's avatar

Help with files deleting when i push a change to heroku

Dunno what is going wrong here but Im using heroku as my server for my app. Users can upload files which locally is going into my public folder.

If i upload it to herkou the app works it uploads the file ( dont know where???) but the app creates the link ok and it displays. If I change s line in the code anywhere in the app and redeply then the link is still there but the file has gone?

Any help on this would be greatful

0 likes
6 replies
computerfr33k's avatar
Level 9

Heroku storage is not persistent across deploys because they are rebuilt after each deploy and so anything that isn't part of the git repo is then lost. You will need to use some sort of block storage if you want files to be available across deploys.

And other thing is if you have more than one dyno, uploaded files will not all be available in every dyno either, same goes for when you run a command in a heroku dyno.

computerfr33k's avatar

yes, something that will let you store files persistently outside the heroku filesystem.

GreyhoundIT's avatar

Cheers.

So having some more dificulty in composer.json i have added "league/flysystem-aws-s3-v3": "dev-master"

in config/fileSystems i have changed default to 's3' 'default' => 's3', 'cloud' => 's3',

and set my details in the s3 setting in that file commited and done an heroku push composer update etc still uploading it to heroku

locally its still uploading to the public folder have i missed anywhere?

namespace App;

use Illuminate\Database\Eloquent\Model; use Carbon\Carbon; use App\Http\Requests; use Illuminate\Support\Facades\DB; use Thujohn\Twitter\Facades\Twitter;

public function handelFileUploads(Requests\FixtureUpdateRequest $request, Fixture $fixture, $name) { //get the old record $oldData = $fixture->$name; if ($request->file($name)) { $file = $request->file($name); //set paths if(($name == 'start_sheet_skeleton')||($name == 'start_sheet_official')){ $destinationPath = $fixture->zone->league->name . '/' . $fixture->zone->name . '/' . $fixture->name . '/startsheets/' ; $destinationPath = strtolower($destinationPath); //Convert whitespaces and underscore to dash $destinationPath = preg_replace("/[\s_]/", "-", $destinationPath); }else{ $destinationPath = $fixture->zone->league->name . '/' . $fixture->zone->name . '/' . $fixture->name . '/results/'; $destinationPath = strtolower($destinationPath); //Convert whitespaces and underscore to dash $destinationPath = preg_replace("/[\s_]/", "-", $destinationPath); } //Move Uploaded File $fileName = $file->getClientOriginalName(); $fileName = time() . '-' .preg_replace("/[\s_]/", "-", $fileName); $file->move($destinationPath, $fileName); $path = $destinationPath . $fileName; // tweet that a file has been updated. // $this->sendFixtureUpdateTweet($fixture, $name); return $path; } else { return $oldData; } }

Please or to participate in this conversation.