NativeScript / nativescript-background-http

Background Upload plugin for the NativeScript framework
Apache License 2.0
101 stars 50 forks source link

TypeError: Cannot set property 'NAMESPACE' #205

Closed Szmycu closed 5 years ago

Szmycu commented 5 years ago

I want to send params using this plugin username password as formdata object, without uploading file.

// var file =  "/some/local/file/path/and/file/name.jpg";
    var bghttp = require("nativescript-background-http");
    var url = "MY_DOMAIN";
    //var name = file.substr(file.lastIndexOf("/") + 1);
    var params = [
        //{ name: "username", value: user.email },
        //{ name: "password", value: user.password },
        { name: "uuid", value: "0x3033314230323830303039" }
     ];

// upload configuration
var request = {
        url: url,
        method: "POST",
        headers: {
            "Content-Type": "application/octet-stream"
        },
       // description: "Uploading " + name
    };

var session = bghttp.session("image-upload");    
var task = session.multipartUpload(params, request);   

task.on("error", errorHandler);   
task.on("complete", completeHandler); 

errorHandler(e) {
    alert("received " + e.responseCode + " code.");
    var serverResponse = e.response;
}

completeHandler(e) {
    alert("received " + e.responseCode + " code");
    var serverResponse = e.response;
}

And I got error System.err: TypeError: Cannot set property 'NAMESPACE' of undefined System.err: File: "file:///data/data/org.nativescript.application/files/app/vendor.js, line: 23216, column: 52 System.err: System.err: StackTrace:

Maybe its error caused by file which I do not send. So I have to simulate here sending some file ? Or could I skip files variables and send only params?

elena-p commented 5 years ago

Hi @Szmycu,

You should be able to use the plugin without sending file. I just ran the demo project removing this line and it uploaded successfully.

Regarding the error you got, could you try deleting your apps' platforms and node_modules folders and build your app again?