【发布时间】:2023-03-20 21:58:01
【问题描述】:
我正在调度一个作业来排队我的视频文件,这些文件存储在 s3 上。
一切正常,除非我上传一个 20mb 的视频文件,当我查看我的存储桶时,它说文件是 120b。所以这让我觉得我将路径和文件名作为字符串而不是文件对象上传。
出于某种原因,当我尝试使用 Storage::get() 或 File::get() 获取文件并 dd 结果时,它会显示一堆或随机和疯狂的字符。
好像只能获取到这些奇怪的字符,或者是字符串,不知什么原因获取不到文件对象。
在我的控制器中,我还将它存储在公共磁盘中(稍后我将在我的 Jobs/UploadVideos.php 文件中删除该文件)。
CandidateProfileController.php:
$candidateProfile = new CandidateProfile();
$candidateProfile->disk = config('site.upload_disk');
// Video One
if($file = $request->file('video_one')) {
$file_path = $file->getPathname();
$name = time() . $file->getClientOriginalName();
$name = preg_replace('/\s+/', '-', $name);
$file->storePubliclyAs('videos', $name, 'public');
$candidateProfile->video_one = $name;
}
if($candidateProfile->save()) {
// dispatch a job to handle the image manipulation
$this->dispatch(new UploadVideos($candidateProfile));
return response()->json($candidateProfile, 200);
} else {
return response()->json([
'message' => 'Some error occurred, please try again.',
'status' => 500
], 500);
}
工作/UploadVideos.php:
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $candidateprofile;
public $timeout = 120;
public $tries = 5;
/**
* Create a new job instance.
*
* @param CandidateProfile $candidateProfile
*/
public function __construct(CandidateProfile $candidateProfile)
{
$this->candidateprofile = $candidateProfile;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$disk = $this->candidateprofile->disk;
$filename = $this->candidateprofile->video_one;
$original_file = storage_path() . '/videos/' . $filename;
try {
// Video One
Storage::disk($disk)
->put('videos/'.$filename, $original_file, 'public');
// Update the database record with successful flag
$this->candidateprofile->update([
'upload_successful' => true
]);
} catch(\Exception $e){
Log::error($e->getMessage());
}
}
【问题讨论】:
-
只是为了确认一下,您的 Job 是否打算将文件从您的
public磁盘复制到 S3?