将Nativescript映像复制到Base64,然后获取POST

将Nativescript映像复制到Base64,然后获取POST,post,base64,fetch,nativescript,Post,Base64,Fetch,Nativescript,我怎样才能创建一个适合使用nativescript获取模块发送的图像?下面是一个使用测试服务器的基本演示 "use strict"; var imageSourceModule = require("image-source"); function navigatingTo(args) { var page = args.object; // using icon.png from the template app from res://icon var imgSr

我怎样才能创建一个适合使用nativescript获取模块发送的图像?

下面是一个使用测试服务器的基本演示

"use strict";
var imageSourceModule = require("image-source");

function navigatingTo(args) {

    var page = args.object;

    // using icon.png from the template app from res://icon
    var imgSrc = imageSourceModule.fromResource("icon");
    var imageAsBase64 = imgSrc.toBase64String("PNG");

    fetch("https://httpbin.org/post", {
        method: "POST",
        headers: { "Content-Type": "application/octet-stream" },
        body: imageAsBase64
    }).then(function (r) { return r.json(); }).then(function (result) {
        console.log("Base64String: " + result.data);

        // for (var key in result) {
        //     if (result.hasOwnProperty(key)) {
        //         var element = object[result];
        //         console.log(key);
        //         console.log(element);
        //         console.log("------")
        //     }
        // }

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

正是我要找的!你应该得到一个大胖子。。。竖起大拇指@尼克·利耶夫,有没有在nativescript中将位图转换为Base64的想法?