问题
I'm not too sure how to word this one, but I've got a job called uploadFile
, which uses CloudConvert to convert an uploaded file (e.g PDF) to a JPG.
Used in isolation, it all works great. I can upload a file, it'll be saved to S3, then CloudConvert gets the S3 file, converts it and uploads that too. Perfect.
When it's being used by more than one person at a time, the files get mixed up. The filenames are correct (so the variables themselves must be correct), but the actual image processed is someone else's somehow.
$originalFileName = str_replace('.'.$this->extension, '', $this->actualFileName);
$tempName = $originalFileName.'_'.time().'.jpg';
$fileName = $originalFileName.'_'.time();
Storage::disk('s3')->put($folder.$fileName, $file, 'public');
$fileUrl = Storage::disk('s3')->url($fileName);
CloudConvert::file($fileUrl)
->withOptions([
'quality' => 80,
'resize' => '400x400',
])->to(CloudConvert::S3($tempName));
In the above, the file in Storage->put()
is correct, as is $tempName
and $fileName
. Somehow, the file it's converting is wrong, so the output Jpeg is from someone else's upload.
Does anyone have any idea of what I can try? I'm not even sure where to begin debugging that.
回答1:
Simple Exchange time()
$mark = microtime().rand(10,100);
$tempName = $originalFileName.'_'.$mark.'.jpg';
$fileName = $originalFileName.'_'.$mark;
回答2:
Eugh, okay I finally worked it out. CloudConvert needed to be reinstantiated. See thread here, if anyone ever encounters this again.
来源:https://stackoverflow.com/questions/54663274/laravel-job-overwriting-other-jobs