PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 1, 2022

[FIXED] NotWritableException Can't write image data to path on heroku

 March 01, 2022     heroku, laravel, laravel-5, laravel-5.5     No comments   

Issue

I am trying to save my image data to a folder. It works fine on my localhost but when i moved it to heroku it gives me this error

NotWritableException
Can't write image data to path (https://arcane-peak- 
34431.herokuapp.com/public/images/categories/1527155055.jpg)

Here is my code.

$image = $request->file('image');
    $imagename = $image->getClientOriginalExtension();
    $imagename = time().'.'.$imagename;

    $destinationPath = URL::to('public/images/restaurants');
    $img = Image::make($image->getRealPath());

    $img->resize(100, 100, function ($constraint) {
        $constraint->aspectRatio();
    })->save($destinationPath.'/'.$imagename);

    $destinationPath = URL::to('public/images/restaurants');

    $image->move($destinationPath, $imagename);

What am i doing wrong? And also on my local machine it is the uploaded image that is getting saved but i want my resized image to be saved.Any help would be a life saver


Solution

The bigger issue is that even if you get your image to save it will disappear. Heroku uses an ephemeral filesystem (bold added):

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted. For example, this occurs any time a dyno is replaced due to application deployment and approximately once a day as part of normal dyno management.

Heroku recommends storing user uploads using a third-party service like Amazon S3.



Answered By - Chris
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing