繁体   English   中英

Nativescript将图像上载到使用强大处理输入的Node.js服务器上

[英]Nativescript uploading an image on a nodejs server that uses formidable to handle inputs

嗨,我想知道是否有人可以帮助我通过使用强大js处理输入的nodejs服务器从nativescript上传由相机模块拍摄的图像

这是我的本机代码如下: 在此处输入图片说明

这是下面的nodejs服务器代码: 在此处输入图片说明

尝试将图像转换为Base64String(“ JPG”),仍然不起作用(以下代码:) 在此处输入图片说明

nodejs服务器输出 在此处输入图片说明

但似乎我的本机脚本代码不起作用

这是将图像源从cameraModule转换为base64String并将其传递到服务器的一种非常简单的方法

 cameraModule.takePicture().then(function(imageSource) {
    var imageAsBase64String = imageSource.toBase64String("JPG");
    return imageAsBase64String; 
}).then(function (imageAsBase64String) {
    http.request({
        url: "https://httpbin.org/post",
        method: "POST",
        headers: { "Content-Type": "application/json" },
        content: JSON.stringify({ name: "myName", imageAsString: imageAsBase64String })  
    }).then(function (response) {
        var result = response.content.toJSON();

        console.log("args: " + result.args);
        console.log("origin: " + result.origin);
        console.log("headers: " + result.headers);
        console.log("json: " + result.json);
        console.log("url: " + result.url);
        // console.log("data: " + result.data); // this is our send content

        var myObj = JSON.parse(result.data); // as we are passing a stringied JSON we ahve to parse it
        console.log("my Image Name: " + myObj.name);
        console.log("my Image Base64String: " + myObj.imageAsString);

    }, function (e) {
        console.log("Error occurred " + e);
    });
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM