小编Tha*_*Dao的帖子

如何在上传前使用SailsJS Skipper验证文件类型

作为标题,现在我无法在上传之前检查文件类型.我只验证并且在文件上传成功后不允许保存数据.以下是基本代码

updateAvatar : function(data, context, req, res) {
  req.file('avatar').upload({
      dirname: '../../assets/images/avatar'
    }, function (err, files) {

    var allowExts = ['image/png', 'image/gif', 'image/jpeg'];

    if (err)
      return res.serverError(err);

    if (files.length === 0) 
      return res.badRequest('No file was uploaded!');

    if (allowExts.indexOf(files[0].type) == -1)
      return res.badRequest('File type is not supported!');

    // save database here
  });
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做正确的代码?对不起,我的英语不好!非常感谢!

javascript node.js sails.js bluebird skipper

9
推荐指数
1
解决办法
1024
查看次数

Youtube API - 请求元数据指定了无效的视频描述

我知道这个问题是重复的,但现象不同。

我使用 Youtube API PHP 上传我的视频。不幸的是,它捕获了错误:

{
    "status": "fail",
    "mess": "Failed to start the resumable upload (HTTP 400: youtube.video, The request metadata specifies an invalid video description.)"
}
Run Code Online (Sandbox Code Playgroud)

我检查了描述。使用mb_strlen()少于 5000 个字符的返回结果。

$title = mb_substr($title, 0, 100);
$description = mb_substr($description , 0, 4999);
$tags = array_slice($tags, 0, 15);

$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle($title);
$snippet->setDescription($description);
$snippet->setTags($tags);
$snippet->setCategoryId("22");

$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";

$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
Run Code Online (Sandbox Code Playgroud)

有一些特殊字符存在:<>, |, '(single qoute), (), …

php youtube-api

5
推荐指数
1
解决办法
2588
查看次数

如何使用 Laravel 5.5 从多态关系中检索数据?

我是 Laravel 的新手。我正在开发一个演示,Polymorphic Relations遵循文档

我设置了3张表:

--Users
  --id
  --username
--Posts
  --id
  --summary
  --published
--Images
  --id
  --link
  --alt
  --image_id
  --image_type
Run Code Online (Sandbox Code Playgroud)

App\Models\Users

public function scopeWithImages()
{
    return static::with('images')->get();
}

public function images()
{
    return $this->morphMany('App\Models\Images', 'image');
}
Run Code Online (Sandbox Code Playgroud)

App\Models\Posts

public function scopeWithImages()
{
    return static::with('images')->get();
}

public function images()
{
    return $this->morphMany('App\Models\Images', 'image');
}
Run Code Online (Sandbox Code Playgroud)

App\Models\Images

public function scopeWithUsers ()
{
    return static::with('users')->get();
}

public function users()
{
    return $this->morphedByMany('App\Models\Users', 'image');
}

public function posts()
{
    return $this->morphedByMany('App\Models\Posts', 'image');
}
Run Code Online (Sandbox Code Playgroud)

Users我通过调用和建模轻松获得了图像集合 …

php laravel laravel-5

5
推荐指数
1
解决办法
7139
查看次数

如何用光标url减小图像的大小?

我有一张尺寸为105x105的图片.我使用这个CSS脚本将它用作游标:

.class_1 .child_1 {
    cursor: url(theBell.png) 20 20, auto;
}
Run Code Online (Sandbox Code Playgroud)

将鼠标移到元素上时会出现图像,但图像太大.

我不知道如何减少光标的大小.

我有一些搜索,但没有找到积极的结果.

css html5 css3

4
推荐指数
1
解决办法
5120
查看次数

如何使用ffmpeg按时间向视频添加文本

我用命令创建我的幻灯片:

"ffmpeg" -f concat -safe 0 -i /path/to/text.txt -i /path/to/audio.mp3 -vsync vfr -pix_fmt yuv420p /path/to/output.mp4
Run Code Online (Sandbox Code Playgroud)

text.txt 的内容

file '/path/to/img1.jpg'
duration 6
file '/path/to/img2.jpg'
duration 6
file '/path/to/img3.jpg'
duration 6
file '/path/to/img4.jpg'
duration 6
file '/path/to/img5.jpg'
duration 6
file '/path/to/img6.jpg'
duration 6
Run Code Online (Sandbox Code Playgroud)

该视频已完美创建。现在我想为显示的每个图像添加标题。例子:

  • img1.jpg 显示,显示标题 Title 1
  • img2.jpg 显示,显示标题 Title 2
  • img3.jpg 显示,显示标题 Title 3

我搜索了很多,但得到了任何解决方案。任何人都可以帮助我。我被卡住了

ffmpeg

4
推荐指数
1
解决办法
5749
查看次数

合并视频后,时长过长 - ffmpeg

我有包含内容的文件 txt

file intro.mp4
file video.mp4
file outtro.mp4
Run Code Online (Sandbox Code Playgroud)

持续时间为10s, 178s, 13s

我使用 ffmpeg 通过以下命令将 3 个文件合并为一个:

ffmpeg -f concat -i "file.txt" -vcodec copy -acodec copy "endfile.mp4"
Run Code Online (Sandbox Code Playgroud)

的持续时间endfile.mp4更长11分钟 ( 660s)。

我有一个问题,which params of video affect to merge?并且which common params to merge another videos?

我的英语真的太差了。对不起:)
本周工作顺利!

P/S 文件的详细信息:

intro.mp4

ffprobe version N-82885-g6d09d6e Copyright (c) 2007-2016 the FFmpeg developers<br>
    built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)<br>
    configuration: --prefix=/root/ffmpeg_build …
Run Code Online (Sandbox Code Playgroud)

ubuntu ffmpeg

3
推荐指数
1
解决办法
3013
查看次数

ffmpeg - 如何提高性能?

我正在尝试加快速度并为 mp4 视频添加背景。这花了很多时间。

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.91*PTS[i]; [0:a]atempo=1.1000[p]" -map "[i]" -map "[p]" output-1.mp4 2>&1
Run Code Online (Sandbox Code Playgroud)

完成上述命令大约需要 30 分钟。输入文件的大小约为30-40MB,并不算太大。
接下来,我运行以下命令为视频添加背景,大约需要 30 分钟(背景分辨率为 1280x720)

ffmpeg -i output-1.mp4 -i background.png -filter_complex "overlay=0:0" output.mp4 2>&1
Run Code Online (Sandbox Code Playgroud)

它使我的系统非常慢,并且性能非常差。
我可以做些什么来改进?

ffmpeg

3
推荐指数
1
解决办法
6744
查看次数

如何在Laravel 5.5中自动将数据从请求模型映射到模型


我想提交包含许多字段的表单.
作为文档

$flight = new Flight;
$flight->name = $request->name;
$flight->param1 = $request->param1;
$flight->param2 = $request->param2;
...
$flight->param_n = $request->param_n;
$flight->save();
Run Code Online (Sandbox Code Playgroud)

如果有太多的字段,这是一个坏主意.
我正在寻找任何类似的脚本:

$flight = new Flight;
$flight->save($request->all());
Run Code Online (Sandbox Code Playgroud)

$request->all()功能得到了不必要的领域
最好的方法是什么?

php laravel laravel-5

3
推荐指数
1
解决办法
4145
查看次数

通过控制器助手授权:方法authorize()不存在 - Laravel 5.5

我定义了PostPolicy.php处理谁可以访问操作。
我正在尝试处理更新帖子的 PUT 请求,但它似乎无法正常工作。

namespace App\Policies;

use App\Models\Users;
use App\Models\Posts;
use Illuminate\Auth\Access\HandlesAuthorization;

class PostPolicy
{
    use HandlesAuthorization;

    public function view(Users $user, Posts $posts)
    {
        return true;
    }

    public function create(Users $user)
    {
        return true;
    }

    public function update(Users $user, Posts $posts)
    {
        return true; //$user->id === $posts->user_id;
    }

    public function delete(Users $user, Posts $posts)
    {
        return $user->id === $posts->user_id;
    }
}
Run Code Online (Sandbox Code Playgroud)

我在以下位置注册了此政策AuthServiceProvider.php

protected $policies = [
    'App\Model' => 'App\Policies\ModelPolicy',
    App\Models\Posts::class => App\Policies\PostPolicy::class,
];
Run Code Online (Sandbox Code Playgroud)

我的路线:

Route::put('post/update/{id}', 'CMS\PostController@update');
Run Code Online (Sandbox Code Playgroud)

最后,这是我的控制器 …

php laravel laravel-5

1
推荐指数
1
解决办法
3128
查看次数