Thread Alternative zu CGI - Rostis Framework (19 answers)
Opened by rosti at 2018-07-17 10:11

Gustl
 2018-07-17 20:11
#188646 #188646
User since
2011-01-27
443 Artikel
BenutzerIn
[Homepage]
user image
Hallo, danke für deine Antworten und deine Mühe.

ich habe es hinbekommen:

JS:
Code: (dl )
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);


Perl:
Code (perl): (dl )
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;


Und die progressbar funktioniert auch. :)

Vielen Dank.

Gruß
Last edited: 2018-07-17 22:26:43 +0200 (CEST)

View full thread Alternative zu CGI - Rostis Framework