在不使用NativeScript(TypeScript + Angular)中使用Formdata的情况下发布图像和其他



我累了这个将表单数据与 Angular 中的其他字段一起发送不适合我。

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

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

NativeScript不支持FormData。您有 2 个选项,

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

最新更新