mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-21 21:03:42 +00:00
Transmit the media type
This commit is contained in:
parent
c0eac366fe
commit
e004e20352
1 changed files with 10 additions and 5 deletions
|
@ -46,6 +46,7 @@ use Friendica\Model\Item;
|
|||
use Friendica\Model\Post;
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Util\Images;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Subscriber\Oauth\Oauth1;
|
||||
|
@ -219,7 +220,7 @@ function twitter_post_hook(array &$b)
|
|||
} catch (\Throwable $th) {
|
||||
Logger::warning('Error while uploading image', ['image' => $image, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||
Worker::defer();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -265,13 +266,17 @@ function twitter_upload_image(int $uid, array $image)
|
|||
$photo = Photo::createPhotoForExternalResource($image['url']);
|
||||
}
|
||||
|
||||
$picturedata = Photo::getImageForPhoto($photo);
|
||||
|
||||
$mimetype = $photo['type'] ?: Images::getMimeTypeByData($picturedata);
|
||||
|
||||
$parameters = [
|
||||
'name' => 'media_data',
|
||||
'contents' => base64_encode(Photo::getImageForPhoto($photo))
|
||||
'contents' => base64_encode($picturedata)
|
||||
];
|
||||
|
||||
Logger::info('Uploading', ['uid' => $uid, 'image' => $image]);
|
||||
$media = twitter_post($uid, 'https://upload.twitter.com/1.1/media/upload.json', 'multipart', [$parameters]);
|
||||
Logger::info('Uploading', ['uid' => $uid, 'size' => strlen($parameters['contents']), 'image' => $image]);
|
||||
$media = twitter_post($uid, 'https://upload.twitter.com/1.1/media/upload.json?' . http_build_query(['media_type' => $mimetype]), 'multipart', [$parameters]);
|
||||
|
||||
if (isset($media->media_id_string)) {
|
||||
$media_id = $media->media_id_string;
|
||||
|
@ -287,7 +292,7 @@ function twitter_upload_image(int $uid, array $image)
|
|||
Logger::info('Metadata create', ['uid' => $uid, 'data' => $data, 'return' => $ret]);
|
||||
}
|
||||
} else {
|
||||
Logger::error('Failed upload', ['uid' => $uid, 'image' => $image['url'], 'return' => $media]);
|
||||
Logger::error('Failed upload', ['uid' => $uid, 'size' => strlen($parameters['contents']), 'image' => $image['url'], 'return' => $media]);
|
||||
throw new Exception('Failed upload of ' . $image['url']);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue