Skip to content
Advertisement

laravel deployed on google app engine doesn’t upload files

I am trying to upload a file, I am using laravel 4 and deploy on google app engine. Locally file upload works, but then when deploy with google app engine it doesn’t. Here is my code:

view:

{{ Form::model($v, array('files' => true,'route' => array('upload.image', $v->id),'method' => 'post','class'=>'form-horizontal','id'=>'upload-images')) }}
            {{ Form::file('image') }}
            <br>
            {{ Form::submit('Add Photo', array('class' => 'btn btn-primary' )) }}
            {{ Form::close() }}

controller

$file = Input::file('image');
        dd($file);
        $destinationPath = 'img_gallery/';
        $extension = $file->getClientOriginalExtension();
        $filename = 'img_' . $id . '.' . $extension;
        $file->move($destinationPath, $filename);

        $car = Car::find($id);
        $car->Pic = $filename;
        $car->save();
        return Redirect::to('/');

and it displays an array with file attr. But when deployed with google app engine this code returns NULL. After readin google app engine documentation for php I understood that the problem is that in google app engine you can’t write to filesystem app, and in this link I found that code for php without laravel and tried to combine with mine like below:

upload_test.blade.php

require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';

use googleappengineapicloud_storageCloudStorageTools;

$options = [ 'gs_bucket_name' => 'images_upload'];
$upload_url = CloudStorageTools::createUploadUrl('upload.handler', $options);
?>
<div class="body">
    <form action="<?php echo $upload_url ?>" enctype="multipart/form-data" method="post">
        <input type="file" name="uploaded_files" size="40">
        <input type="submit" value="Send">
    </form>
</div>

controller

 public function upload_image($id) {
        $file = Input::file('image');
        dd($file);
}

route

Route::group(array('before' => 'auth'), function() {
    Route::post('upload_handler', array('as' => 'upload.handler', 'uses' => 'CarController@upload_handler'));
});

controller

public function upload_handler() {
        var_dump($_FILES);
    }

But this displays:

Symfony Component HttpKernel Exception MethodNotAllowedHttpException

Which I know that is an error because form post is not pointing to a route, instead to a variable. The image is stored in google app engine but the problem is that this code doesn’t post to controller in order to save path of file in DB. I have tried other ways but no result. I also followed step by step section 6 in this. Furthermore I tried Ajessup package but no result.

Advertisement

Answer

With this line:

$upload_url = CloudStorageTools::createUploadUrl('upload.handler', $options);

the first arg should be a URL– try removing the quotes (assuming that upload.handler points to where you want it to), or try replacing that arg with the actual URL that the app should redirect to.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement