Php 带有文件输入的表单在GAE上不起作用
嘿,我正在尝试从多部分/表单数据表单中的输入文件上载一个文件。我使用的是symfony5.1。代码在我的本地服务器上运行得很好,但在Google App Engine prod环境中提交表单时返回500错误 这是我的控制器代码:Php 带有文件输入的表单在GAE上不起作用,php,symfony,google-app-engine,google-cloud-storage,symfony5,Php,Symfony,Google App Engine,Google Cloud Storage,Symfony5,嘿,我正在尝试从多部分/表单数据表单中的输入文件上载一个文件。我使用的是symfony5.1。代码在我的本地服务器上运行得很好,但在Google App Engine prod环境中提交表单时返回500错误 这是我的控制器代码: $advertiserID = $this->getUser()->getAdvertiserId(); $form = $this->createForm(UploadCreativeFormType::class, null, [
$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()
]);
这是我的应用程序。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)$
如果我转储表单,它会抛出相同的错误,我甚至无法获取表单对象,因此我猜是关于文件输入或caché目录的问题
任何帮助都将不胜感激!提前谢谢 谢谢!我刚刚为gcloud安装了错误记录器。(正常日志显示了一个500错误,没有更多信息)。盖伊似乎错过了作曲家西蒙尼/默剧。我重新安装了它,它的工作就像一个符咒。
再次感谢 您需要检查开发人员控制台>日志以查看错误说明。我打赌它无法解析这个相对路径:
'keyFilePath'=>“../gcloud\u auth.json'
。将gcloud\u auth.json
放在应用程序的根目录下(与app.yaml
目录相同),然后删除。/