1
0
Fork 0
mirror of synced 2024-06-28 19:20:25 +12:00

Allow file uploads from explorer

This commit is contained in:
Jake Barnby 2022-12-13 15:43:29 +13:00
parent 4868b8f8ec
commit aa7e326ce9
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
3 changed files with 15 additions and 2 deletions

View file

@ -86,6 +86,7 @@ App::post('/v1/graphql')
}
$type = $request->getHeader('content-type');
if (\str_starts_with($type, 'application/graphql')) {
$query = parseGraphql($request);
}
@ -195,6 +196,7 @@ function parseMultipart(array $query, Request $request): array
{
$operations = \json_decode($query['operations'], true);
$map = \json_decode($query['map'], true);
foreach ($map as $fileKey => $locations) {
foreach ($locations as $location) {
$items = &$operations;
@ -207,9 +209,13 @@ function parseMultipart(array $query, Request $request): array
$items = $request->getFiles($fileKey);
}
}
$query['query'] = $operations['query'];
$query['variables'] = $operations['variables'];
unset($query['operations']);
unset($query['map']);
return $query;
}

View file

@ -417,7 +417,14 @@ App::post('/v1/storage/buckets/:bucketId/files')
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Maximum bucket file size is larger than _APP_STORAGE_LIMIT');
}
$file = $request->getFiles('file');
// GraphQL multipart spec adds files with index keys
if (empty($file)) {
$file = $request->getFiles(0);
}
if (empty($file)) {
throw new Exception(Exception::STORAGE_FILE_EMPTY);
}

View file

@ -73,9 +73,9 @@ class StorageClientTest extends Scope
]
]),
'map' => \json_encode([
'file' => ["variables.file"]
'0' => ["variables.file"]
]),
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
'0' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
];
$file = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([