Skip to content
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

upload/media throws an exception when providing an http resource #799

Closed
williamlang opened this issue Oct 3, 2019 · 5 comments
Closed

Comments

@williamlang
Copy link

williamlang commented Oct 3, 2019

private function uploadMediaNotChunked($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);
}

is_readable on an http resource will be false while file_get_contents will return true. Because of this, uploading a file using a url will never work.

echo is_readable('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');

echo file_get_contents('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');

@abraham
Copy link
Owner

abraham commented Oct 3, 2019

This is expected. Twitter does not support URLs for file uploads. The file has to be on your server and uploaded.

@abraham abraham closed this as completed Oct 3, 2019
@williamlang
Copy link
Author

williamlang commented Oct 3, 2019

I do this right now, though. And it works.

The library uses file_get_contents which does support it. You are base64 encoding a file, so while Twitter may not support it, the library certain could and, I guess based on opinion should?

@abraham
Copy link
Owner

abraham commented Oct 4, 2019

The library should not hide from the developer that a file is being downloaded to their server and then uploaded to Twitter. Previously if you had a large image on another server, developers would use a URL and think that Twitter was getting the file directly. The library was updated to make it clear that the file must be on the developers server and be uploaded directly to Twitter.

#681 is tracking adding a file class where the developer can chose to use a file on disk, a remote file that will be temporarily downloaded, or some other means.

@williamlang
Copy link
Author

Fair enough, thanks!

@jackwh
Copy link

jackwh commented Nov 9, 2021

This has caught people out using Laravel's Twitter Notifications package. Because Laravel abstracts the filesystem, it's not currently possible to attach an image if, for example, it's stored on AWS S3.

In this issue thread, I've suggested two simple fixes that could be made to the uploadMediaNotChunked() function which would resolve this. I'm not sure how far off #681 is, but this would be very helpful for Laravel users in the meantime...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants