我试图在 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"}]
,它有效