Skip to content

Commit d475c5f

Browse files
committed
Update form import/export to be compatible with tempAssetUploadFs
1 parent 2d22bd1 commit d475c5f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/controllers/ImportExportController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace verbb\formie\controllers;
33

44
use verbb\formie\Formie;
5+
use verbb\formie\helpers\Assets;
56
use verbb\formie\helpers\HandleHelper;
67
use verbb\formie\helpers\ImportExportHelper;
78
use verbb\formie\helpers\StringHelper;
@@ -51,7 +52,7 @@ public function actionImport(): ?Response
5152
}
5253

5354
$filename = 'formie-import-' . gmdate('ymd_His') . '.json';
54-
$fileLocation = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
55+
$fileLocation = Assets::getTempPath($filename);
5556

5657
move_uploaded_file($uploadedFile->tempName, $fileLocation);
5758

@@ -65,7 +66,7 @@ public function actionImportConfigure(string $filename): ?Response
6566
{
6667
$request = $this->request;
6768

68-
$fileLocation = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
69+
$fileLocation = Assets::getTempPath($filename);
6970

7071
if (!file_exists($fileLocation)) {
7172
throw new HttpException(404);
@@ -148,7 +149,7 @@ public function actionImportComplete(): ?Response
148149
$filename = $request->getParam('filename');
149150
$formAction = $request->getParam('formAction');
150151

151-
$fileLocation = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
152+
$fileLocation = Assets::getTempPath($filename);
152153

153154
if (!file_exists($fileLocation)) {
154155
throw new HttpException(404);

src/helpers/Assets.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ class Assets extends CraftAssets
1212
// Static Methods
1313
// =========================================================================
1414

15+
public static function getTempPath(string $filename): string
16+
{
17+
// Use `tempAssetUploadFs` if set for Servd/Cloud support
18+
$fs = Craft::$app->getAssets()->getTempAssetUploadFs();
19+
20+
if ($fs instanceof LocalFsInterface) {
21+
$path = sprintf('%s/%s', rtrim($fs->getRootPath(), '/'), $filename);
22+
23+
return FileHelper::normalizePath($path);
24+
}
25+
26+
return sprintf('%s/%s', rtrim(Craft::$app->getPath()->getTempPath(), '/'), $filename);
27+
}
28+
1529
public static function getFullAssetFilePath(Asset $asset): string
1630
{
1731
$volume = $asset->getVolume();

0 commit comments

Comments
 (0)