【问题标题】:Media upload filesize(): stat failed for uploads error Laravel - TwitterOauth媒体上传文件大小():上传错误 Laravel 的统计失败 - TwitterOauth
【发布时间】:2021-07-26 15:19:11
【问题描述】:

我正在使用 Abraham 的 https://twitteroauth.com/ 包从 Laravel 应用程序发送 Twitter 消息。

我还使用 Laravel 任务调度来调度消息。 我还需要用这个包发送媒体 Twitter 消息。它工作正常。但它不适用于 laravel 任务计划控制台命令。

我的twitter消息发送代码是这样的:

                $screenshot = $this->takeScreenShot();
                $media = $this->twitter->upload('media/upload', array('media' => "uploads/$screenshot", 'media_type' => 'image/png'), true);
                $parameters = [
                    'status' => $twitterMsg,
                    'media_ids' => implode(',', [$media->media_id_string])
                ];
                $result = $this->twitter->post('statuses/update', 

$parameters);

它会抛出这个错误:

filesize(): stat failed for uploads/screenshots_1620116807.png

at vendor/abraham/twitteroauth/src/TwitterOAuth.php:417
  413▕             'shared',
  414▕         ];
  415▕         $base = [
  416▕             'command' => 'INIT',
➜ 417▕             'total_bytes' => filesize($parameters['media']),
  418▕         ];
  419▕         $allowed_parameters = array_intersect_key(
  420▕             $parameters,
  421▕             array_flip($allowed_keys),

    +3 vendor frames
4   app/Services/TwitterService.php:219
    Abraham\TwitterOAuth\TwitterOAuth::upload() 

如何解决控制台任务命令的这个错误?

谢谢

【问题讨论】:

  • 错误信息很可能意味着,它没有在您提供的路径下找到文件。与运行创建正常前端输出的脚本时相比,任务调度程序中的执行上下文可能不同,可能具有不同的工作目录。尝试给出完整的绝对路径。

标签: php laravel twitter-oauth


【解决方案1】:

这可能是因为您在media 上提供了uploads/screenshots_1620116807.png 的相对路径。尝试传递到媒体的绝对路径,例如通过storage_pathpublic_path 辅助方法:

$media = $this->twitter->upload('media/upload', [
    'media' => public_path("uploads/$screenshot"),
    'media_type' => 'image/png',
], true);

【讨论】:

  • 其实并没有存储在存储路径中。我曾经存储在公共路径中。
  • @tcetin 没有什么不同,请改用public_path
  • 您正在尝试将此更改设置为 twitter 包。我更新了问题。请看一下。
猜你喜欢
  • 2018-02-13
  • 1970-01-01
  • 2014-11-17
  • 2017-06-01
  • 1970-01-01
  • 2022-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多