HTTP-Upload-FlowJs
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/HTTP/Upload/FlowJs.pm view on Meta::CPAN
Default 1024
The minimum chunk size is required since the file type detection
works on the first chunk. If the first chunk is too small, its file type
cannot be checked.
B<forceChunkSize> - force all chunks to be less or equal than C<maxChunkSize>
Default: true
Otherwise, the last chunk will be greater than or equal to C<maxChunkSize>
(the last uploaded chunk will be at least this size and up to two the size).
Note: when C<forceChunkSize> is C<false> it only make C<chunkSize> value in
L</jsConfig> equal to C<maxChunkSize/2>.
B<simultaneousUploads> - simultaneously allowed uploads per file
Default 3
This is just an indication to the Javascript C<flow.js> client
if you pass it the configuration from this object. This is not enforced
in any way yet.
B<allowedContentType> - subroutine to check the MIME type
The default is to allow any kind of file
If you need more advanced checking, do so after you've determined a file
upload as complete with C<< $flowjs->uploadComplete >>.
B<fileParameterName> - The name of the multipart POST parameter to use for the
file chunk
Default C<file>
=back
More interesting limits would be hard maxima for the number of pending
uploads or the number of outstanding chunks per user/session. Checking
these would entail a call to C<glob> for each check and thus would be
fairly disk-intensive on some systems.
=cut
sub new( $class, %options ) {
croak "Need a directory name for the temporary upload parts"
unless $options{ incomingDirectory };
$options{ maxChunkCount } ||= 1000;
$options{ maxFileSize } ||= 10_000_000;
$options{ maxChunkSize } ||= 1024*1024;
$options{ minChunkSize } //= 1024;
$options{ forceChunkSize } //= 1;
$options{ simultaneousUploads } ||= 3;
$options{ mime } ||= MIME::Detect->new();
$options{ fileParameterName } ||= 'file';
$options{ allowedContentType } ||= sub { 1 };
bless \%options => $class;
};
=head2 C<< $flowjs->incomingDirectory >>
Return the incoming directory name.
=cut
sub incomingDirectory( $self ) {
$self->{incomingDirectory};
};
=head2 C<< $flowjs->mime >>
Return the L<MIME::Detect> instance.
=cut
sub mime($self) {
$self->{mime}
};
=head2 C<< $flowjs->jsConfig >>
=head2 C<< $flowjs->jsConfigStr >>
# Perl HASH
my $config = $flowjs->jsConfig(
target => '/upload',
);
# JSON string
my $config = $flowjs->jsConfigStr(
target => '/upload',
);
Create a JSON string that encapsulates the configuration of the Perl
object for inclusion with the JS side of the world.
=cut
sub jsConfig( $self, %override ) {
# The last uploaded chunk will be at least this size and up to two the size
# when forceChunkSize is false
my $chunkSize = $self->{maxChunkSize};
$chunkSize = $chunkSize/2 unless $self->{forceChunkSize}; # / placate Filter::Simple
+{
(
map { $_ => $self->{$_} } (qw(
simultaneousUploads
forceChunkSize
))
),
chunkSize => $chunkSize,
testChunks => 1,
withCredentials => 1,
uploadMethod => 'POST',
%override,
};
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.388 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )