5 mogupload -- Upload data to a MogileFS installation
10 $ mogupload [options] --file="-" < filename
12 $ mogupload --trackers=host --domain=foo --class=bar \
13 --key="/hello.jpg" --file="input.jpg"
15 $ echo "why hello" | mogupload [opts] --key="world" --file="-"
21 =item --trackers=host1:7001,host2:7001
23 Use these MogileFS trackers to negotiate with.
25 =item --domain=<domain>
27 Set the MogileFS domain to use.
31 Set the class to use. Will use default class if not specified
35 A key to store the file under. Can be an arbitrary string.
37 =item --file="<filename|->"
39 A local file to upload. If '-', read file from STDIN instead.
45 Dormando E<lt>L<dormando@rydia.net>E<gt>
49 Licensed for use and redistribution under the same terms as Perl itself.
59 my $util = MogileFS
::Utils
->new;
60 my $usage = "--trackers=host --domain=foo --key='/hello.jpg' --file='./hello.jpg'";
61 my $c = $util->getopts($usage, qw
/class=s key=s file=s/);
63 my $mogc = $util->client;
65 my $filename = $c->{file
};
66 die "Must specify a file to upload with --file" unless $filename;
70 if ($filename eq '-') {
74 die "Could not stat " . $filename unless defined $size;
75 open($fh, "< $filename") or die "Could not open " . $filename;
78 my $mf = $mogc->new_file($c->{key
}, $c->{class}, $size);
80 die "Error opening MogileFS file: " . $mogc->errstr;
84 while (my $read = read($fh, $buf, 1024 * 1024)) {
85 die "error reading file" unless defined $read;
90 die "Error writing file: " . $mogc->errcode . ": " . $mogc->errstr;