Handle relative file path

This commit is contained in:
Daniel Berteaud 2017-09-13 16:56:21 +02:00
parent ffac9f3632
commit 7ee62e253d
3 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,7 @@ It requires the following perl modules
* File::HomeDir
* File::Basename
* File::MimeInfo
* File::Spec
* Path::Tiny
* Getopt::Long
* URI::Escape

View File

@ -18,6 +18,7 @@ Requires: perl(Getopt::Long)
Requires: perl(JSON)
Requires: perl(File::Basename)
Requires: perl(File::MimeInfo)
Requires: perl(File::Spec)
Requires: perl(Path::Tiny)
Requires: perl(URI::Escape)
Requires: perl(Term::ReadKey)

View File

@ -10,6 +10,7 @@ use Config::Simple;
use File::HomeDir;
use File::MimeInfo;
use File::Basename;
use File::Spec;
use URI::Escape;
use Path::Tiny;
use Term::ReadKey;
@ -241,11 +242,12 @@ sub send_file {
# Sending a file is a 2 steps operation. First we need to upload the file to the media store
# And then we post the uri on the room
debug("Uploading file $opt->{file} to the media store");
$opt->{file} = File::Spec->rel2abs($opt->{file});
my $uri = $opt->{server} . '/_matrix/media/v1/upload?access_token=' . $opt->{access_token} . '&filename=' . basename($opt->{file});
my $resp = send_request({
uri => $uri,
content_type => mimetype $opt->{file},
content => path( $opt->{file} )->slurp_raw
content_type => mimetype($opt->{file}),
content => path($opt->{file})->slurp_raw
});
debug("File upload response is\n" . to_json(from_json($resp->decoded_content), { pretty => 1 }));
die "Error uploading file\n" unless ($resp->is_success);