-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
You must supply a readable file error when using withImage and AWS S3 #64
Comments
What does your |
The following works:
This doesn't:
https://s3.eu-central-1.amazonaws.com/xxx/images/5.jpg is a publicly available image and can be viewed in a browser - where xxx is the name of my S3 bucket. |
I can't check myself right now, but if I remember correctly you need to provide a "local" path and cannot use a URL to an image. |
Ok thanks
|
This is still an issue. The problem seems to be in the /**
* Private method to upload media (not chunked) to upload.twitter.com.
*
* @param string $path
* @param array $parameters
*
* @return array|object
*/
private function uploadMediaNotChunked(string $path, array $parameters)
{
if (
!is_readable($parameters['media']) ||
($file = file_get_contents($parameters['media'])) === false
) {
throw new \InvalidArgumentException(
'You must supply a readable file',
);
}
$parameters['media'] = base64_encode($file);
return $this->http(
'POST',
self::UPLOAD_HOST,
$path,
$parameters,
false,
);
} I would argue the call to Alternatively, you could change the |
Thanks, how can I re-produce this issue? |
@christophrumpel If you set up a Laravel Notification class like this, then try to send it out, it should throw an error when it attempts to read the image from a remote URL: <?php
namespace App\Notifications;
class ExampleTweet extends \Illuminate\Notifications\Notification
{
public function via(mixed $notifiable): array
{
return [\NotificationChannels\Twitter\TwitterChannel::class];
}
public function toTwitter(mixed $notifiable): \NotificationChannels\Twitter\TwitterStatusUpdate
{
return (new \NotificationChannels\Twitter\TwitterStatusUpdate('Lorem ipsum dolor'))
->withImage('https://images.unsplash.com/photo-1595433707802-6b2626ef1c91');
}
} In this example I'm passing an image URL in from Unsplash. In the context of the original issue, this might be a URL to a remote image on S3. Because the file is remote (yet abstracted by Laravel's I think changing the |
Thanks, everyone, I just gave it another look. We are using the https://github.com/abraham/twitteroauth package to interact with the Twitter API. The code @jackwh was referring to is from this package. It also seems to be a limitation from the Twitter API itself, that you can only pass local images. (abraham/twitteroauth#824 (comment)) So the only thing I can think of currently would be to download the images with this package and then pass the local link. But this is actually something that should be done in the application itself because I can't tell where to download it and users also need to know that this is happening. So the easiest option would be to download the image you need yourself and pass the local path. I know this is not a great way to handling it but I don't see a another good solution right now. |
Thanks for clarifying @christophrumpel — my mistake, I hadn't noticed the It looks like they don't want to change the way In the meantime, I'm working around this by simply copying the file from S3 to |
No worries and thanks for the update. A file class would be nice indeed. |
-To fill a need for conversion of media URLs to base64 (negating the need for storing the media prior to uploading) -Added public function `shipit` that privately calls to -Added private function `uploadMediaNotStored`
-To fill a need for conversion of media URLs to base64 (negating the need for storing the media prior to uploading) -Added public function `shipit` that privately calls to -Added private function `uploadMediaNotStored`
The following code where $image is a publicly accessible jpeg image causes an error:
return (new TwitterStatusUpdate($message))->withImage($image);
The error is:
"message": "You must supply a readable file", "exception": "InvalidArgumentException", "file": "D:\\project\\vendor\\abraham\\twitteroauth\\src\\TwitterOAuth.php"
Any thoughts as to why this is happenign?
The text was updated successfully, but these errors were encountered: