I'm running into an interesting problem after hosting my Laravel application on Heroku. I am using S3 to store all images, and the database is hosted on Postgres. Locally I am able to upload files of any size (15mb+) to S3, and have Image Intervention generate their thumbnails properly. However after hosting on Heroku I cannot upload any images over 1MB. In their limitation section, Heroku caps the HTTP response buffering at 1MB (Link: http://ift.tt/2uo7sbN). I am not experienced enough to tell if this is the issue though....
The console errror I get when trying to upload a larger image previews out to this:
(1/1) ErrorException Trying to get property of non-object in ImageUploadController.php (line 23)
Here is my ImageUploadController code:
<?php
namespace App\Http\Controllers\Images;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Listing;
use Storage;
use App\Traits\ImageUploader;
use App\Models\Photo;
class ImageUploadController extends Controller
{
use ImageUploader;
public function store(Listing $listing, Request $request)
{
$this->authorize('imageUD', $listing);
$photo=$this->uploadImages($request->file('file'), $listing->id);
return response()->json([
'photo_id' => $photo->id,
'listing_id' => $listing->address
]);
}
public function destroy(Listing $listing, Photo $photo, Request $request)
{
$this->authorize('imageUD', $listing);
Storage::disk('s3')->delete($photo->original_name);
Storage::disk('s3')->delete($photo->thumbnail_name);
$photo->delete();
}
}
And here is my ImageUploader Trait:
<?php
namespace App\Traits;
use App\Models\Photo;
use Image;
use Storage;
use Aws\S3;
trait ImageUploader
{
//takes in array of images and a listing id
public function uploadImages($image, $id)
{
if($image){
$imageName = time().$image->getClientOriginalName();
$imageNameOriginal = "original-" . $imageName;
$imageNameThumbnail = "thumbnail-" . $imageName;
$img = Image::make($image->getRealPath());
$imageThumbnail= $img->resize(null, 225, function ($constraint) {
$constraint->aspectRatio();
})->resizeCanvas(300, 225)->stream();
//$s3 = Aws\S3\S3Client::factory();
$s3=Storage::disk('s3')->put($imageNameOriginal, file_get_contents($image), 'public');
$s3=Storage::disk('s3')->put($imageNameThumbnail, $imageThumbnail->__toString(), 'public');
$imageNameOriginalURL = Storage::disk('s3')->url($imageNameOriginal);
$imageNameThumbnailURL = Storage::disk('s3')->url($imageNameThumbnail);
//create Database Settings
$photo = new Photo;
$photo->original_name=$imageNameOriginal;
$photo->thumbnail_name=$imageNameThumbnail;
$photo->original_url=$imageNameOriginalURL;
$photo->thumbnail_url=$imageNameThumbnailURL;
$photo->listing_id=$id;
$photo->save();
return $photo;
// }
}
return;
}
public function getFileNames($image)
{
dd($image);
$imageName = time().$image->getClientOriginalName();
$imageNameOriginal = "original-" . $imageName;
$imageNameThumbnail = "thumbnail-" . $imageName;
return [$imageNameOriginal, $imageNameThumbnail];
}
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tqHeIF
via IFTTT
Aucun commentaire:
Enregistrer un commentaire