Leser: 18
1
2
3
4
5
6
7
8
9
10
11
12
13
<input type="file" id="uplink" onchange="upload()">
<script>
function upload(){
var xhr = new XMLHttpRequest();
xhr.open('PUT','/cgi-bin/nph-echo.cgi');
xhr.onload = function(){
console.log( this.response );
};
/* Einfach den Blob senden */
xhr.send( document.getElementById('uplink').files[0] );
}
</script>
read(STDIN, my $binary, $ENV{CONTENT_LENGTH});
2018-07-16T12:08:58 GustlMusst du von ihm kaufen.PS: Wo finde ich eigentlich dein Framework? Hab gestern Nacht noch ein wenig gesucht aber nix finden können. Oder ist dein Framework nur für dich vorgesehen?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
use Data::Dumper; my $bs = bSerialize->new(); # All in One: Hash, Array, Hash of Hashes (EAV) my $bin = $bs->av2bin({ addr => $bs->av2bin( { name => 'foo', vname => 'bar', city => 'NY', nix => '', garnix => undef } ), nums => $bs->array2bin( [undef, 0, 1, 2, 3, 9] ), eav => $bs->eav2bin({ env => \%ENV, sig => \%SIG }) }); print Dumper $bin, $bs->bin2av( \$bs->bin2av(\$bin)->{addr} ), $bs->bin2array( \$bs->bin2av(\$bin)->{nums} ), $bs->bin2eav( \$bs->bin2av(\$bin)->{eav} );
read(STDIN, my $binary, $ENV{CONTENT_LENGTH});
1
2
3
4
5
6
7
8
9
10
11
var myfiles = document.getElementById('myfiles').files;
var arr = new Array();
console.log(myfiles.length + " Files")
for(var i = 0; i < myfiles.length; i++){
var file = myfiles[i];
arr.push(i, 'name', file.name);
arr.push(i, 'type', file.type ? file.type : 'application/octet-stream');
arr.push(i, 'bin', file);
}
arr.push('param','upload','1');
var content = bSerialize.array2bin(arr);
my @array = $bs->bin2array( \$binary );
1
2
3
4
5
6
7
8
var eav = {
file.name: {
name: file.name,
size: file.size,
type: file.type,
binary: file
}
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Public und unabhängig verwendbar # application/x-www-form-urlencoded sub qparse{ my $self = shift; my $rawdata = shift; my %param = (); # Punkte in Parameternamen erlauben my @pie = split /[;&]/, $rawdata; foreach my $p(@pie){ my ($pname, $val) = split(/=/, $p, 2); next unless $pname; next unless defined $val; $val =~ s/\+/ /g; $val =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; push @{$param{$pname}}, $val; } return \%param; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var files = document.getElementById('myfiles').files
var eav = {};
console.log(files.length + " Files")
for(var i = 0; i < files.length; i++){
var c = {
name : files[i].name,
size : files[i].size,
type : files[i].type ? files[i].type : 'application/octet-stream',
binary : files[i]
}
eav[files[i].name] = c;
}
console.log(eav)
var content = bSerialize.eav2bin(eav);
var xhr = new XMLHttpRequest();
xhr.open('POST','pl/upload.pl');
xhr.onload = function(){
console.log("response:");
console.log( this.response );
};
var progressBar = document.querySelector('progress');
xhr.upload.onprogress = function(e) {
console.log(e);
if (e.lengthComputable) {
progressBar.value = (e.loaded / e.total) * 100;
}
};
xhr.send( content );
console.log("content:");
console.log(content);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/usr/bin/perl -w use strict; #use CGI; #use CGI::Carp qw(fatalsToBrowser); use Data::Dumper; use bytes; use lib '../modules'; use bSerialize; binmode STDOUT; binmode STDIN; read(STDIN, my $binary, $ENV{CONTENT_LENGTH}); my @header = ( 'Content-Type: text/html', # HTTP/1.0 200 OK ); push @header, "Content-Length: $ENV{CONTENT_LENGTH}"; print join("\r\n", @header), "\r\n\r\n$binary"; my $bs = bSerialize->new; my $bin2eav1 = $bs->bin2eav( \$binary ); open DEBUG, "> ../debug.txt" or die "../debug.txt: $!"; foreach my $key (keys %$bin2eav1) { print DEBUG $key."\n"; print DEBUG "name: ".$bin2eav1->{$key}->{name}."\n"; print DEBUG "size: ".$bin2eav1->{$key}->{size}."\n"; print DEBUG "type: ".$bin2eav1->{$key}->{type}."\n"; print DEBUG "binary: ".$bin2eav1->{$key}->{binary}."\n"; print DEBUG "--------------------------------------\n"; open FH0, "> ../".$bin2eav1->{$key}->{name} or die ": $!"; print FH0 $bin2eav1->{$key}->{binary} ; close FH0; } close DEBUG; exit;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// params ist das Array [{},{},{},,]
// Wir brauchen eine andere Datenstruktur
var eav = { param: {request:1} };
// Der Array Index wird zur Object ID
for(a = 0; a < params.length; a++){
eav[a] = params[a];
}
var xhr = new XMLHttpRequest();
xhr.open('POST','%url%');
xhr.setRequestHeader('Content-Type','eav/binary');
xhr.onload = function(){
// Callback
};
xhr.send( EAV.eav2blob( eav ));