Presto's avatar

Javascript Image Upload Script Returns Error 500

Hello everyone,

I'm trying to add http://www.Croppic.net when the script is ran I get an error 500 in Chrome dev tools. If I use DHC (Chrome plugin) to test my endpoint it works fine. I have also tried passing in the _token as well without much luck.

Here is my controller

use File;
use Image;
use Input;
use Storage;
use Session;

class AvatarController extends Controller
{
    public function upload($id)
    {
        $file = Input::file('avatar');
        $name = $file->getClientOriginalName();
        $path = storage_path('app/temp/' . $name);
        $s3path = strtoupper(Session::get('country')) . '/realtor/' . $id . '/avatar/' . $name;

        Image::make( $file->getRealPath() )->fit(300)->save( $path );
        Storage::disk('s3')->put( $s3path, File::get($path));
        Storage::Delete( 'temp/' . $name );
        $response = [
            "status" => 'success',
            "url" => 'https://s3.' . env('S3_REGION') . '.amazonaws.com/' . env('S3_BUCKET') . '/' . $s3path,
            "width" => 300,
            "height" => 300
        ];
        return $response;
    }
}

Here is a screenshot of what I get in DHC. https://dl.dropboxusercontent.com/u/9319663/Screen%20Shot%202015-06-08%20at%209.17.51%20AM.png

0 likes
2 replies
Presto's avatar

Looking at the documentation on http://www.croppic.net/#optionTarget-uploadData they have the option to pass data using:

uploadData:{}

So I included the _token in their like so:

uploadData:{
    "_token":"\{{ csrf_token() \}}" // without slashes :)
}

But that does not fix it ether :(

Presto's avatar
Presto
OP
Best Answer
Level 6

Stupid, stupid, stupid!!!

In my example above and in my screenshot you will notice that I'm looking for a field called avatar, but Croppic sends that field titled as "img" so I'm looking for a field "avatar" the reason it worked when I used DHC is because I was sending the field as "avatar" but Croppic was not, so once I noticed that Croppic was sending it as img, I updated my upload script in my controller and BAM! it started working, Wahoo!!

Please or to participate in this conversation.