英文:
Using flutter flutter_image_compress to upload base64 compressed file but cant uncompress in python
问题
以下是翻译好的部分:
I can successfully upload a file to s3 by
- using flutter_image_compress to compress and
- converting the file to base64.
现在我可以解码文件:
base64_string = open("img1b95b3ed9e494595b01610f06d9f074b.txt", "r").readlines()[0]
Now after that all fails:
msg = base64.b64decode(base64_string)
inflated = zlib.decompress(msg)
inflated = zlib.decompress(msg)
zlib.error: Error -3 while decompressing data: incorrect header check
So what is the proper method to decode in python from using the flutter flutter_image_compress package?
Thanks
PS this is now I compress in flutter:
以下是未翻译的部分,因为它们是代码或者与翻译无关的内容:
Future<Uint8List?> testCompressFile(File file) async {
var result = await FlutterImageCompress.compressWithFile(file.absolute.path,
quality: 100,
keepExif: true
);
return result;
}
英文:
I can successfully upload a file to s3 by
- using flutter_image_compress to compress and
- converting the file to base64.
Now I can decode the file:
base64_string = open("img1b95b3ed9e494595b01610f06d9f074b.txt", "r").readlines()[0]
Now after that all fails:
msg = base64.b64decode(base64_string)
inflated = zlib.decompress(msg)
inflated = zlib.decompress(msg)
zlib.error: Error -3 while decompressing data: incorrect header check
So what is the proper method to decode in python from using the flutter flutter_image_compress package?
Thanks
PS this is now I compress in flutter:
Future<Uint8List?> testCompressFile(File file) async {
var result = await FlutterImageCompress.compressWithFile(file.absolute.path,
quality: 100,
keepExif: true
);
return result;
}
答案1
得分: 1
解码Base64将给你一个uint8List
,在Python中,这相当于byteArray
。请尝试将该byteArray
转换为bytes
以获得二进制数据。你不需要使用zlib
:
listOfInt = [1, 2, 3, 4, 5, 6]
byteArray = bytearray(listOfInt)
print(byteArray) # bytearray(b'\x01\x02\x03\x04\x05\x06')
byteObj = bytes(byteArray)
print(byteObj) # b'\x01\x02\x03\x04\x05\x06'
英文:
decoding base64 would give you uint8List
which in python's terms would be a byteArray
. Please try converting that byteArray
into bytes
to gain the binary data. You don't need the zlib
:
listOfInt = [1, 2, 3, 4, 5, 6]
byteArray = bytearray(listOfInt)
print(byteArray) # bytearray(b'\x01\x02\x03\x04\x05\x06')
byteObj = bytes(byteArray)
print(byteObj) # b'\x01\x02\x03\x04\x05\x06'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论