App-MatrixTool
view release on metacpan or search on metacpan
[BUGFIXES]
* Workaround for perl5.18's PV swiping bug during 'pairmap'
* Don't emit blank lines into '.matrix/server-keys' cache
0.06 2016/10/05 19:09:29
[CHANGES]
* Much expanded documentation
* Improved 'help' command's handling of subcommands
[BUGFIXES]
* Fix typo in "image/png" MIME type
* Treat ERR_NO_ADDRESS DNS errors the same as ERR_NO_HOST
0.05 2016/09/23 19:59:34
[CHANGES]
* Implement 'client upload' for uploading content to media repo
* Allow 'client json' to take query parameters
[BUGFIXES]
* Fix unit tests for renamed module
lib/App/MatrixTool/Command/client/upload.pm view on Meta::CPAN
use constant DESCRIPTION => "Upload a file to the media repository";
use constant ARGUMENTS => ( "file", "type?" );
use constant OPTIONS => ();
=head1 NAME
matrixtool client upload - Upload a file to the media repository
=head1 SYNOPSIS
$ matrixtool client -u @me:example.com upload avatar.png
=head1 DESCRIPTION
This command uploads a file to the media repository of a Matrix homeserver,
printing the returned F<mxc://> URL.
Normally the MIME type must be supplied as a second argument, but in the
common case of files whose names end in certain recognised file extensions,
the MIME type can be automatically inferred for convenience.
The recognised extensions are
.jpg, .jpeg image/jpeg
.png image/png
=cut
sub run
{
my $self = shift;
my ( $opts, $file, $type ) = @_;
my $content = read_binary( $file );
unless( defined $type ) {
$type = "image/jpeg" if $file =~ m/\.jp[e]?g$/;
$type = "image/png" if $file =~ m/\.png$/;
defined $type or
die "Type not specified and could not guess it from the filename\n";
}
$self->do_json( POST => "/_matrix/media/r0/upload",
content => $content,
content_type => $type,
)->then( sub {
my ( $result ) = @_;
( run in 1.475 second using v1.01-cache-2.11-cpan-df04353d9ac )