У меня есть один API для загрузки видео, и это дает ответ JSON
success": {
"uid": "****************",
"original_name": "**********.mp4",
"duration": "****"
}
И я хочу, чтобы другой API обновлял видео другие данные после получения этого ответа. Я не понимаю, как действовать для this.
function upload(Request $request)
{
$videofile = $request->file('video');
$validator = Validator::make($request->all(), [
'video' => ['required', 'file', 'mimes:video/mp4,video/mpeg,video/x-matroska,mp4,mov,ogg,video/3gpp,video/3gpp2,video/x-flv,application/x-mpegURL,video/MP2T,video/quicktime,video/x-msvideo,video/x-ms-wmv,application/octet-stream,video/x-ms-asf,image/x-tga'],
]);
if ($validator->fails()) {
return Response::json(array('error' > true, 'msg' => 'Please choose the video to upload'));
} else {
if ($videofile) {
$filename = md5_file($videofile->getRealPath());
$extension = $request->file('video')->getClientOriginalExtension();
$videoId = $filename . time();
$uniqueFilename = $videoId . '.' . $extension;
$path = public_path() . '/videos/';
if ($videofile->move($path, $uniqueFilename)) {
// get video duration
$getID3 = new \getID3;
$videoToUpload = $request->file('video');
$videoPath = public_path() . '/videos/' . $uniqueFilename;
$file = $getID3->analyze($videoPath);
$playtime_seconds = $file['playtime_seconds'];
$videoDuration = gmdate("H:i:s", $playtime_seconds);
$myVideoHour = gmdate('H', strtotime($videoDuration));
if ($myVideoHour == 00) {
$myVideoDuration = gmdate('i:s', strtotime($videoDuration));
} else {
$myVideoDuration = $videoDuration;
}
$output = array(
'uid' => $videoId,
'original_name' => $uniqueFilename,
'duration' => $videoDuration
);
return response()->json(['success' => $output], $this->successStatus);
}
}
}
}
как передать этот вывод в другую функцию для обновления других данных видео.
моя другая функция ---
function uploadData(Output $output)
{
if ($output) {
$validator = Validator::make($request->all(), [
'title' => ['required', 'string', 'max:255'],
'keywords' => ['required', 'string', 'max:255'],
'channel_id' => ['required', 'not_in:0'],
'description' => ['max:2000'],
'visibility' => ['required', 'in:public,unlisted,private'],
'thumbnail' => ['image', 'mimes:jpeg,png,jpg,gif', 'max:6144', 'nullable'],
'uid' => ['max:2000'],
'original_name' => ['max:2000'],
'duration' => ['max:2000'],
]);
if ($validator->fails()) {
return response()->json(['error' => $validator->errors()], 401);
}
$video = new Video;
$user = Auth::user();
// print_r($user);
// exit;
$user_id = $user->id;
// $user_id = auth()->user()->id;
$Channels = Channel::Where('channels.user_id', $user_id)->get();
$video->user_id = $user_id;
$video->uid = $videoId;
$video->title = $request->title;
$video->original_name = $uniqueFilename;
$video->keywords = $request->keywords;
$video->thumbnail_url = $request->thumbnail_url;
$video->description = $request->description;
$video->visibility = $request->visibility;
$video->category_id = $request->category_id;
$video->channel_id = $request->channel_id;
$video->duration = $videoDuration;
$video->allow_votes = $request->has('allow_votes');
$video->allow_comments = $request->has('allow_comments');
if (!empty($request->get('playlistid'))) {
$video->playlist_id = $request->get('playlistid');
} elseif (!empty($request->playlist_id)) {
$video->playlist_id = $request->playlist_id;
}
$filename = '';
$site_url = url('/');
if ($request->hasFile('thumbnail')) {
$image = $request->file('thumbnail');
$filename = $video->id . '_' . time() . '_' . uniqid(rand()) . '.' . $image->getClientOriginalExtension();
$img = Image::make($image->getRealPath())->resize(720, 404);
//$img->save($filename);
$path = 'images/thumbnails/';
$img->save("$path$filename");
$url = $site_url . '/' . $path;
$thumbnails = $url . $filename;
$video->thumbnail_url = $thumbnails;
}
$videoUrl = url('/videos/' . $request->uid);
$video->save();
return response()->json([
"message" => "video record created"
], 201);
}
}
It показывает, что вывод неизвестен.