Overview
I would like to push the current file upload process to a queue. When the file upload has completed, an email will be sent out to the user that the upload process complete. This idea has been implemented because large sets of files will be uploaded and we would like the user to navigate to other parts of the system while the upload process is being carried out.
What's in place right now !
Currently I am iterating through all the files that are meant to be uploaded (in my controller ) and creating an array of the uploaded files. I am doing this because Laravel does not allow me to send models to the queue. Here is the code
if (Input::hasFile('files')) {
$filesarr = Input::file('files');
foreach($filesarr as $fileitem)
{
array_push($filesArray, array(
'realpath'=>$fileitem->getRealPath(),
'originalname' => $fileitem->getClientOriginalName(),
'originalextension'=>$fileitem->getClientOriginalExtension(),
'mime' =>$fileitem->getClientMimeType(),
'size' =>$fileitem->getClientSize(),
'maxFileSizeAllowed' => $fileitem ->getMaxFileSize(),
'isUpdateMode' => 1,
'orealPath' => $fileitem->getOriginalPath()
));
}
}
I am then sending this array to the queue.
Queue::push('TopicQueue', array ('dataArr' =>$filesArray));
In my queue fire method, I am getting the array of uploaded files. The code follows
$files = $dataArray['$filesArray'];
Now, I am trying to use laravel method of file uploading , so again, I try to create an instance of Laravel's UploadFile class. The code for that follows
foreach($allFiles as $file)
{
Log::info("File is :" .var_export($file,true));
Log::info('Going to upload file : '.$file['originalname']);
try
{
$uploadFile = new UploadedFile($file['realpath'],$file['originalname'],$file['mime'],$file['size']);
}
catch(Exception $ex)
{
Log::info('The error is : '.$ex->getMessage());
}
}
but here I am encountering an issue (which is correct) . The instantiation fails with the message
The file does not exist.
This is happening within the constructor of the uploadfile class itself.
I also tried to searlize and unserialize the class, but apparently the UploadFile is not serializable.
Someone care to help, please !
Thanks