Skip to content

Commit 746b2cc

Browse files
committed
Improvements on detect public files.
1 parent bd4e866 commit 746b2cc

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

ProcessMaker/Http/Controllers/Api/ProcessRequestFileController.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,17 @@ private function saveUploadedFile(UploadedFile $file, ProcessRequest $processReq
327327
$user = pmUser();
328328
$originalCreatedBy = $user ? $user->id : null;
329329

330-
$data_name = $laravelRequest->input('data_name', $file->getClientOriginalName());
330+
$parentRequest->loadMissing('process');
331+
$isPublicFilesProcess = optional($parentRequest->process)->package_key === 'package-files/public-files';
332+
333+
$fileName = $file->getClientOriginalName();
334+
$data_name = $laravelRequest->input('data_name', $fileName);
335+
if ($isPublicFilesProcess) {
336+
// File manager builds URLs as #/public/{data_name} (see Media::getManagerUrlAttribute).
337+
// Key media by the real client file name so multi-file uploads and /public-files/{name}
338+
// stay correct even when the client sends a shared or wrong data_name per file.
339+
$data_name = $fileName;
340+
}
331341
$rowId = $laravelRequest->input('row_id', null);
332342
$parent = (int) $laravelRequest->input('parent', null);
333343
$multiple = $laravelRequest->input('multiple', null);
@@ -356,7 +366,7 @@ private function saveUploadedFile(UploadedFile $file, ProcessRequest $processReq
356366
$media = $model
357367
->addMedia($file)
358368
->withCustomProperties([
359-
'data_name' => $file->getClientOriginalName(),
369+
'data_name' => $data_name,
360370
'parent' => $parent != 0 ? $parent : null,
361371
'row_id' => $rowId,
362372
'createdBy' => $originalCreatedBy,

0 commit comments

Comments
 (0)