如何在nativescript中上载图像

如何在nativescript中上载图像,nativescript,Nativescript,我正在尝试通过nativescript后台http插件上传图像 这是我的代码: var session = bghttp.session("image-upload"); var request = { url: 'http://localhost:4200/', method: "POST", headers: { "Content-Type": "application/octet-stream", "File-Name": imageFile.name },

我正在尝试通过
nativescript后台http
插件上传图像

这是我的代码:

var session = bghttp.session("image-upload");
var request = {
  url: 'http://localhost:4200/',
  method: "POST",
  headers: {
    "Content-Type": "application/octet-stream",
    "File-Name": imageFile.name
  },
  description: "{ 'uploading': " + imageFile.name + " }"
};

var task = this.session.uploadFile(path, request);
当我尝试构建我的应用程序时,它将显示错误:

TypeError: Cannot set property 'NAMESPACE' of undefined
错误行正好是这一行:

var task = this.session.uploadFile(path, request);

有什么想法吗?

我有一个解决方案给你。现在,在后端服务器上使用文件流方法可以轻松地使用nativescript后台http上载图像


点击上面的链接,这将帮助您了解nativescript core。

使用插件存储库中的演示检查您的版本和代码。演示的操作与此完全相同(上传照片)。请注意,上述演示使用的是一个虚拟节点服务器,该服务器应通过
npm run start
从演示服务器文件夹启动(以便能够测试图像上传)