使用 googleapis 在 Google Drive 中保存带有字母“ąćęśżźół”的 Json/txt 文件 - 未处理的异常:无效参数

问题描述 投票:0回答:0

我试图在 Google Drive 中保存简单的 Json 文件,但在最后一步我遇到了一个错误:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument (Not a byte value at index 19: 0x17c): Instance of 'CodeUnits'
排成一排
final response = await driveApi.files.create(driveFile, uploadMedia: media);

我的 Json 是这样的:

[{"info":{"name":"Dżejson","weight":35,"address":null,"notes":"some notes"}]

登录到谷歌工作,保存简单的文本文件工作,但保存文件像 Json 的字符串/文本文件与字母 'ąćęśżźół' 不工作

import 'package:googleapis/drive/v3.dart' as drive;

drive.DriveApi driveApi = await _getDriveApi();

String contents = await readJson();

final Stream<List<int>> mediaStream = Future.value(contents.codeUnits).asStream().asBroadcastStream();

var media = drive.Media(mediaStream, contents.length);

final response = await driveApi.files.create(driveFile, uploadMedia: media);

...

Future<drive.DriveApi?> _getDriveApi() async {
    final _googleSignIn = signIn.GoogleSignIn.standard(scopes: [drive.DriveApi.driveFileScope,]); 
    final signIn.GoogleSignInAccount? account = await _googleSignIn.signIn();

    //final googleUser = await googleSignIn.signIn();
    final headers = await account?.authHeaders;
    if (headers == null) {
      return null;
    }

    final client = GoogleAuthClient(headers);
    final driveApi = drive.DriveApi(client);
    return driveApi;
}

我尝试不使用波兰语字母“ż”

[{"info":{"name":"Dzejson","weight":35,"address":null,"notes":"some notes"}]
,它有效

flutter google-drive-api
© www.soinside.com 2019 - 2024. All rights reserved.