taron133
2020-10-26 aa8d874c8a3287d41d26566ae32b6ed8d4557ff9
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
 * @preserve formdatabuilder.js (c) 2015 KNOWLEDGECODE | MIT
 */
(function (global) {
    'use strict';
 
    var FormDataBuilder = function () {
        this.boundary = '----WebKitFormBoundary' + Math.random().toString(36).slice(2);
        this.type = 'multipart/form-data; boundary=' + this.boundary;
        this.crlf = '\r\n';
        this.pairs = [];
    };
 
    FormDataBuilder.prototype.append = function (name, value) {
        var type = Object.prototype.toString.call(value),
            enc = function (str) {
                // WebKit's behavior
                return str.replace(/\r/g, '%0D').replace(/\n/g, '%0A').replace(/"/g, '%22');
            },
            pair = {
                disposition: 'form-data; name="' + enc(name || '') + '"'
            };
 
        // WebKit's behavior
        if (!name) {
            return;
        }
        if (type === '[object File]' || type === '[object Blob]') {
            pair.disposition += '; filename="' + enc(value.name || 'blob') + '"';
            pair.type = value.type || 'application/octet-stream';
            pair.value = value;
        } else {
            pair.value = String(value);
        }
        this.pairs.push(pair);
    };
    FormDataBuilder.prototype.getBlob = function () {
        var array = [], i, len = this.pairs.length;
 
        for (i = 0; i < len; i++) {
            array.push('--' + this.boundary + this.crlf + 'Content-Disposition: ' + this.pairs[i].disposition);
            if (this.pairs[i].type) {
                array.push(this.crlf + 'Content-Type: ' + this.pairs[i].type);
            }
            array.push(this.crlf + this.crlf);
            array.push(this.pairs[i].value);
            array.push(this.crlf);
        }
        array.push('--' + this.boundary + '--' + this.crlf);
        return global.Blob ? new Blob(array) : new global.FileReaderSync().readAsArrayBuffer((function (data) {
            var Builder = global.BlobBuilder || global.WebKitBlobBuilder || global.MSBlobBuilder,
                blob = new Builder();
 
            (data || []).forEach(function (d) {
                blob.append(d);
            });
            return blob.getBlob();
        }(array)));
    };
 
    global.FormDataBuilder = FormDataBuilder;
 
}(this));