Remove temporary files once they're in the analysis queue following an upload
This commit is contained in:
parent
f4f4de1b34
commit
24f2155a35
@ -317,6 +317,8 @@ class PhotoController extends Controller
|
|||||||
Log::error('Image upload failed.', ['error' => $photoFile->getError(), 'reason' => $photoFile->getErrorMessage()]);
|
Log::error('Image upload failed.', ['error' => $photoFile->getError(), 'reason' => $photoFile->getErrorMessage()]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if ($request->has('photo_id'))
|
if ($request->has('photo_id'))
|
||||||
{
|
{
|
||||||
@ -376,6 +378,11 @@ class PhotoController extends Controller
|
|||||||
|
|
||||||
$isSuccessful = true;
|
$isSuccessful = true;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
@unlink($photoFile->getRealPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->isXmlHttpRequest())
|
if ($request->isXmlHttpRequest())
|
||||||
@ -422,6 +429,8 @@ class PhotoController extends Controller
|
|||||||
$temporaryFolder = sprintf('%s/%s', sys_get_temp_dir(), MiscHelper::randomString());
|
$temporaryFolder = sprintf('%s/%s', sys_get_temp_dir(), MiscHelper::randomString());
|
||||||
@mkdir($temporaryFolder);
|
@mkdir($temporaryFolder);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$queueStorage = AnalysisQueueHelper::getStorageQueueSource();
|
$queueStorage = AnalysisQueueHelper::getStorageQueueSource();
|
||||||
|
|
||||||
$mimeType = strtolower($archiveFile->getMimeType());
|
$mimeType = strtolower($archiveFile->getMimeType());
|
||||||
@ -450,7 +459,7 @@ class PhotoController extends Controller
|
|||||||
{
|
{
|
||||||
if ($fileInfo->getFilename() == '__MACOSX' || substr($fileInfo->getFilename(), 0, 1) == '.')
|
if ($fileInfo->getFilename() == '__MACOSX' || substr($fileInfo->getFilename(), 0, 1) == '.')
|
||||||
{
|
{
|
||||||
@rmdir($fileInfo->getPathname());
|
@rmdir($fileInfo->getRealPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -459,19 +468,19 @@ class PhotoController extends Controller
|
|||||||
if (substr($fileInfo->getFilename(), 0, 1) == '.')
|
if (substr($fileInfo->getFilename(), 0, 1) == '.')
|
||||||
{
|
{
|
||||||
// Temporary/hidden file - skip
|
// Temporary/hidden file - skip
|
||||||
@unlink($fileInfo->getPathname());
|
@unlink($fileInfo->getRealPath());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = getimagesize($fileInfo->getPathname());
|
$result = getimagesize($fileInfo->getRealPath());
|
||||||
if ($result === false)
|
if ($result === false)
|
||||||
{
|
{
|
||||||
// Not an image file - skip
|
// Not an image file - skip
|
||||||
@unlink($fileInfo->getPathname());
|
@unlink($fileInfo->getRealPath());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$photoFile = new File($fileInfo->getPathname());
|
$photoFile = new File($fileInfo->getRealPath());
|
||||||
$queuedFileName = $queueStorage->uploadToAnalysisQueue($photoFile, $queueUid);
|
$queuedFileName = $queueStorage->uploadToAnalysisQueue($photoFile, $queueUid);
|
||||||
|
|
||||||
$photo = new Photo();
|
$photo = new Photo();
|
||||||
@ -504,6 +513,13 @@ class PhotoController extends Controller
|
|||||||
$rabbitmq = new RabbitMQService();
|
$rabbitmq = new RabbitMQService();
|
||||||
$rabbitmq->queueItem($queueItem);
|
$rabbitmq->queueItem($queueItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@unlink($fileInfo->getRealPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
@rmdir($temporaryFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect(route('albums.analyse', [
|
return redirect(route('albums.analyse', [
|
||||||
|
Loading…
Reference in New Issue
Block a user