FileTransfer writing in my binary?


#1

My code

ionic


upload (file: any, url) {

    let options: FileUploadOptions = {
        httpMethod: 'POST'
    };

    for (var i = 0; i <file.length; i ++) {
        this.fileTransfer.upload (file [i], url, options, false)
            .then ((date) => {
                console.log (data);
            }, (err) => {
                console.log (err);
            });
    }
}

node server


app.post (’/ upload’, function (req, res) {
req.setEncoding (‘binary’);
var body = ‘’;

req.on (‘data’, function (data) {
body + = data;
});

req.on (‘end’, function () {
fs.writeFileSync (__ dirname + ‘/00.jpg’, body, ‘binary’, function (err) {
console.log (err);
});
});
});


the problem is!
that the filetransfer is writing this in my binary, leaving my file useless! unless I manually remove it.

binary


  • +++++
    Content-Disposition: form-data; name = “file”; filename = "image.jpg"
    Content-Type: image / jpeg

ÿØÿà JFIF ÿÛ C a ÿÀ Ð " ÿ
ÿ}!! 1 #
(Continued)

  • +++++

(I.e.
Anyone know how I can handle this? !!!
Thank you

I’m brazilian