user3660185
user3660185

Reputation:

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 google\appengine\api\cloud_storage\CloudStorageTools;

$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.

Upvotes: 1

Views: 1763

Answers (3)

Kusal Dissanayake
Kusal Dissanayake

Reputation: 752

A better alternative to this scenario is uploading file as a set of chucks of size that the request can handle.

Example project - https://github.com/pionl/laravel-chunk-upload-example

Upvotes: 0

Amy U.
Amy U.

Reputation: 2237

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.

Upvotes: 1

Bogdan.Nourescu
Bogdan.Nourescu

Reputation: 905

I think it's a permission problem if it works with your local dev server and not your remote server. To fix it try the following:

  1. Go to cloud console
  2. Go to your project, storage, cloud storage, storage browser
  3. Check if your bucket exists and if it has permission of write for your service account name that can be found in the appengine dashboard

I recommend that you use the default GCS bucket:

  1. Go to appenigne dashboard, application settings
  2. If you have a button that says something like: generate cloud integration project, click on it
  3. If there is a Google Cloud Storage Bucket listed there, use that as an alternative to your "images_upload" bucket. It should be similar to "appid.appspot.com"

Upvotes: 0

Related Questions