我正在运行一个返回javascript缓冲区对象的云函数。类似于这样的东西:
functions
.region("europe-west2")
.runWith({ timeoutSeconds: 20, memory: "128MB", })
.https
.onCall(async (data, context) => {
const buffer = await sharp(imagePath).toBuffer();
return buffer;
});在我的存储库中,我调用这个云函数如下所示:
Future<Uint8List> resizeImage({required String fileName}) async {
try {
final result = await firebaseFunctions
.httpsCallable('resizeImage')
.call<dynamic>({'fileName': fileName});
//printing result.data returns a IdentityMap<String, dynamic>.
} on FirebaseFunctionsException catch (e) {
//handle error
}
}当我打印result.data.runtimeType时,它是一个地图对象,如下所示:
{12: 239, 2938: 293}
如何将此地图转换为UInt8List?
发布于 2022-08-06 11:55:50
结果是,我必须得到IdentityMap的值并将它们转换为一个列表。
返回的数据不是{12: 239, 2938: 293},而是{0: 239, 1: 293, 2:382},因此它是基于索引的。我是这样解决的:
final bytes = List<int>.from(result.data.values);
return Uint8List.fromList(bytes);https://stackoverflow.com/questions/73241226
复制相似问题