How to add media conversion to existing media instance - laravel

I have my existing $media instance and I would like to generate a thumbnail at $seconds.
I tried:
$media->manipulations = [
'thumb' => [
'height' => '250',
'extractVideoFrameAtSecond' => $seconds,
],
];
$media->save();
But get this error:
Can not convert image. Unknown operation extractVideoFrameAtSecond used

Related

How to validate files in Laravel?

It seems like some ios Devices (newer ones I believe, iPhones and iPads) and versions aren't able to validate files properly.
I'm trying to validate an image, a resume and 3 videos.
I keep getting one of these two errors:
"resume_id": [
"The resume id must be a file of type: doc, docx, pdf."
]
And I always upload a .doc or pdf file.
Or
"video_one_id": [
"The video one id must be a file of type: avi ,mpeg, mpeg4, mov."
]
"video_two_id": [
"The video two id must be a file of type: avi ,mpeg, mpeg4, mov."
]
"video_three_id": [
"The video three id must be a file of type: avi ,mpeg, mpeg4, mov."
]
And I always upload .mov files. I find usually this happens when I take a video on my iphone and upload it. My client also tried the same thing on his brand new iPad and also had no success.
Here is my code.
CandidateProfileRequest.php:
public function rules()
{
return [
'date_of_birth' => 'required',
'experience' => [
'required',
new MaxWordsRule(),
],
'skills' => [
'required',
new MaxWordsRule(350),
],
'job_title' => 'required',
'resume_id' => 'required|file|mimes:doc,docx,pdf',
];
}
CandidateProfileController.php:
public function store(CandidateProfileRequest $request)
{
if ($request->hasFile('video_one_id')
&& $request->hasFile('video_two_id')
&& $request->hasFile('video_three_id')
&& $request->hasFile('photo_id')) {
$request->validate([
'video_one_id' => 'file|mimes:avi ,mpeg, mpeg4, mov|max:30720',
'video_two_id' => 'file|mimes:avi ,mpeg, mpeg4, mov|max:30720',
'video_three_id' => 'file|mimes:avi ,mpeg, mpeg4, mov|max:30720',
'photo_id' => 'image|mimes:jpeg, png, jpg|max:5120'
]);
}
}
I also tried using mimetypes instead of mimes in my validation rules, but still I get the errors above.
On my Macbook Pro Laptop everything works, it's just on my iPhone and my clients iPad.
What am I doing wrong?
you can validate file like this way
$validator = Validator::make([ 'pdf' => $request->file('pdf'), 'extension' => strtolower($request->file('pdf')->getClientOriginalExtension()),
], ['pdf' => 'required', 'extension' => 'required|in:pdf,html,txt', ], ['pdf.required' => 'This field is required', 'extension.required' => 'This field is required','extension.in' => 'This field only accept pdf,html,txt extension',]);

Send nested array via Laravel Http Client

I want to send request to an API website containing nested params via Laravel Http Client (Laravel 7.x)
$params = [
'type' => 'books',
'variables' => [
'color' => 'red',
'size' => 'large'
]
]
I want my url to like this:
http://example.com/?type=books&variables={"color":"red","size":"large"}
encoded above url:
http://example.com/?type=books&variables=%7B%22color%22%3A%22red%22%2C%22size%22%3A%22large%22%7D
But when I use:
Http::get('http://example.com', $params);
The API server returns error.
But when I use:
Http::get('http://example.com/?type=books&variables={"color":"red","size":"large"}');
It works well.
So how can I convert my params array into url ?
(I don't have access to API server)
try json_encode()
$params = [
'type' => 'books',
'variables' => json_encode([
'color' => 'red',
'size' => 'large'
])
]
$url = "http://example.com?".http_build_query($params);
Http::get($url);
and http_build_query()
ref link https://www.php.net/manual/en/function.http-build-query.php

FFPROBE not supported on window machine

I'm using the PHP-FFMpeg repository to do some video work inside my Laravel application, but I'm encountering some issues setting it up
ffprobe failed to execute command
return [
'default_disk' => 'local',
'ffmpeg' => [
// 'binaries' => env('FFMPEG_BINARIES', 'ffmpeg'),
'ffmpeg.binaries' => 'C:/binaries/ffmpeg/bin/ffmpeg.exe',
'threads' => 12,
],
'ffprobe' => [
//'binaries' => env('FFPROBE_BINARIES', 'ffprobe'),
'ffprobe.binaries' => 'C:/binaries/ffmpeg/bin/ffprobe.exe',
],
'timeout' => 3600,
];

Multiple File Upload Validation Message Problem

Cake3.6:
I am validating a form field which allows multiple files to be uploaded:
$this->Form->input('listing_images. ', ['type' => 'file', 'multiple' => 'multiple']);
I have a custom validation provider which correctly validates the multiple images:
$validator ->add('listing_images', 'listing_images', [
'rule' => [
'dimensions', [
'min' => ['w' => 100, 'h' => 100],
'max' => ['w' => 1600, 'h' => 1600]
]
],
'message' => 'Maximum image size is 1600 x 1600 pixels',
'provider' => 'custom'
]);
The problem is that when validation fails the validation error does not appear below the field. If make the file upload single file only and name is 'listing_images' the validation error does appear.
Why does it not work for multiple?
While it may work partially, the trailing dot syntax that you are using isn't supported (and the trailing space only makes things worse), the form helper will not be able to find the field based on that name.
You can use the name option to specify a name with trailing brackets as required for a multiple file upload HTML input, while passing the regular field name that the form helper understands:
echo $this->Form->control('listing_images', [
'type' => 'file',
'name' => 'listing_images[]',
'multiple' => 'multiple',
]);

How to create thumbnail and store it in another folder using CI3.1.2?

I am using CI version 3.1.2 to process an image and using Windows 8. My problem is every time i process an image and trying to create a thumbnail, i am countering a message "Unable to save the image. Please make sure the image and file directory are writable". This is occurred when trying to save the copy of thumbnail into different location. Here are my codes processing the image:
$this->original_path = realpath(APPPATH.'../assets/galery/full');
// Uploading image
$config = [
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->original_path,
'max_size' => 2048,
'maintain_ratio' => true,
'file_name' => 'img_'.strtotime(date('d-m-y-H-i-s')), // miss type
'overwrite' => true,
'remove_spaces' => true
];
$this->load->library('upload', $config);
$this->upload->do_upload('galery');
$file_name = $this->upload->file_name;
// Processing image, success processing image
$this->load->library('image_lib');
$img = [
'image_library' => 'gd2',
'source_image' => $this->original_path.'/'.$file_name,
'maintain_ratio' => true,
'width' => 600
];
$this->image_lib->initialize($img);
$this->image_lib->resize();
// This is fail, with message "Unable to save the image... using(var_dump())
$thumb = [
'source_image' => $this->original_path.'/'.$file_name,
'new_image' => '/assets/galery/small',
'maintain_ratio' => true,
'width' => 200
];
$this->image_lib->initialize($thumb);
$this->image_lib->resize();
I've tried different config, like using realpath(APPPATH.'../assets/galery/small'), but still no luck. It is success, by the way, when create config using 'create_thumb'.
But my purpose is, saving that thumbnail in another folder. How can i achieve that?
UPDATE
This change seem to work well. I change realpath(APPPATH.'../assets/galery/full') to realpath(APPPATH.'../assets/galery') and make several change in:
...
'upload_path' => $this->original_path.'/full'
...
'source_image' => $this->original_path.'/full/'.$file_name
...
'new_image' => $this->original_path.'/small/thumb_'.$file_name
Until now i'm still trying to make my code simple and put it in MY_Model. Thanks for all comment(s). If some one may have better solution, it would be nice to share here.

Resources