首页 > 解决方案 > 在 nativescript(typescript + angular)中不使用 formdata 发布图像和其他信息

问题描述

我厌倦了这个 发送 FormData 与 Angular 中的其他字段 不适合我。

我需要从文件系统访问图像然后发送它。

        let fullPath = path.join(folder.path, "1.png");
        const imageFromLocalFile: ImageSource = <ImageSource> fromFile(fullPath);
        const base64String = imageFromLocalFile.toBase64String("png");

标签: angulartypescriptnativescript

解决方案


NativeScript 不支持 FormData。你有2个选择,

  1. 将图像作为 Base64 字符串发送,看起来您已经知道如何获取 Base64 字符串形式的图像,您可以将其作为 JOSN 正文中的参数发送。
  2. 使用可以直接上传文件的nativescript-background-http插件。

推荐阅读