Skip to content

Commit 04cc125

Browse files
committed
Fixed file param bug
1 parent ef0ac82 commit 04cc125

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/Appwrite/services/functions.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,25 @@
301301
->action(function ( $functionId, $command, $code ) use ($parser) {
302302
/** @var string $functionId */
303303
/** @var string $command */
304-
/** @var string $code */
304+
/** @var file $code */
305305

306306
$client = new Client();
307307
$path = str_replace(['{functionId}'], [$functionId], '/functions/{functionId}/tags');
308308
$params = [];
309309
/** Body Params */
310310
$params['command'] = $command;
311-
$params['code'] = $code;
311+
$cloudFunctionPath = realpath(__DIR__.'/../../../files/'.$code);
312+
$cloudFunctionParentDir = dirname($cloudFunctionPath, 1);
313+
$cloudFunctionDirName = basename($cloudFunctionPath);
314+
if (file_exists($cloudFunctionPath) === false ) {
315+
throw new Exception("Path doesn't exist. Please ensure that the path is within the current directory. ");
316+
}
317+
$archiveName = 'code.tar.gz';
318+
$volumeMountPoint = realpath(__DIR__.'/../../../files/');
319+
exec("tar -zcvf $archiveName -C $cloudFunctionParentDir $cloudFunctionDirName && mv $archiveName $volumeMountPoint");
320+
$archivePath = realpath($volumeMountPoint."/$archiveName");
321+
$cFile = new \CURLFile($archivePath, 'application/x-gzip' , basename($archivePath));
322+
$params['code'] = $cFile;
312323
$response = $client->call(Client::METHOD_POST, $path, [
313324
'content-type' => 'multipart/form-data',
314325
], $params);

app/Appwrite/services/storage.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@
7676
->param('read', [] , new Wildcard() , 'An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true)
7777
->param('write', [] , new Wildcard() , 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true)
7878
->action(function ( $file, $read, $write ) use ($parser) {
79-
/** @var string $file */
79+
/** @var file $file */
8080
/** @var array $read */
8181
/** @var array $write */
8282

8383
$client = new Client();
8484
$path = str_replace([], [], '/storage/files');
8585
$params = [];
8686
/** Body Params */
87-
$params['file'] = $file;
87+
$file = realpath(__DIR__.'/../../../files/'.$file);
88+
if (file_exists($file) === false ) {
89+
throw new Exception("Path doesn't exist. Please ensure that the path is within the current directory. ");
90+
}
91+
$cFile = new \CURLFile($file, 'image/png' , basename($file));
92+
$params['file'] = $cFile;
8893
$params['read'] = !is_array($read) ? array($read) : $read;
8994
$params['write'] = !is_array($write) ? array($write) : $write;
9095
$response = $client->call(Client::METHOD_POST, $path, [

0 commit comments

Comments
 (0)