3

Hey I'm trying to upload a file from an input file in a multipart/form-data form. I'm using Symfony 5.1. Code works great in my local server but it returns a 500 error when submitting the form in Google App Engine prod environment.

Here's my Controller code:

$advertiserID = $this->getUser()->getAdvertiserId();
    $form = $this->createForm(UploadCreativeFormType::class, null, [
        'advertiserId'=>$advertiserID,
    ]);
    $storage = new StorageClient([
        'keyFilePath' => '../gcloud_auth.json'
    ]);
    $bucket = $storage->bucket('rocketlab-space.appspot.com');
    $form->handleRequest($request);


    if ($form->isSubmitted() && $form->isValid()){
        $data = $form->getData();
        $campaign = $data['campaign'];
        $offerId = $campaign->getOfferId();

        $uploadedFile = $data['creative_url'];
        $newFilename = $offerId.'-'.uniqid().'.'.$uploadedFile->guessExtension();
        $path = $uploadedFile->getPathname();
        $mime = $uploadedFile->getMimeType();

        $bucket->upload(fopen($path, 'r'), [
            'name' => $advertiserID.'/'.$offerId.'/'.$newFilename,
            'contentType' => $mime,

        ]);
        $object = $bucket->object($advertiserID.'/'.$offerId.'/'.$newFilename);
        $response = $object->update(['acl' => []], ['predefinedAcl' => 'PUBLICREAD']);
        dd($response);
    }

    return $this->render('sandbox.html.twig',[
        'uploadForm' => $form->createView()
    ]);

This is my App.yaml:

runtime: php73

env_variables:
  APP_ENV: prod
  APP_SECRET: *****
  # Add the DATABASE_URL environment variable
  DATABASE_URL: ****
  GOOGLE_STORAGE_BUCKET: "*****"



handlers:
  # Declare the build and bundles directory as static assets to be served by the
  # App Engine CDN.
  - url: /build
    static_dir: public/build
  - url: /bundles
    static_dir: public/bundles

  # Declare any media files in the public directory as static assets as well.
  - url: /(.*\.(ico|txt|gif|png|jpg))$
    static_files: public/\1
    upload: public/.*\.(ico|txt|gif|png|jpg)$

If I dump the form it throws the same error, I can't even get the form object, so I guess is something about the file input or the caché directory.

Any help will be appreciated! Thanks in advance!

Atomzwieback
  • 585
  • 6
  • 18
  • 1
    You need to check your Developer Console > Logs to see what the error says. My bet is that it can't resolve this relative path: `'keyFilePath' => '../gcloud_auth.json'`. Put `gcloud_auth.json` at the root of your app (same directory as `app.yaml`, and remove the `../` – GAEfan Jul 15 '20 at 05:07

1 Answers1

0

Thanks! I just installed the error logger for gcloud. (normal logs just showed me a 500 error with no more info). It seems GAE was missing the composer symfony/mime. I reinstalled it and its working like a charm. Thanks again!