将base64字符串转换为文件 [英] Convert base64 string to file
问题描述
我正在尝试将base64字符串转换回原始文件.我尝试从中导出这些文件的应用程序仅允许我导出base64字符串.导出将返回base64字符串和文件类型.
I'm trying to convert base64 strings back to the original files. The application from where I try to export these files will only allow me to export in base64 strings. This export returns the base64 string and the filetype.
如何将这些字符串转换回原始文件?我一直在尝试这样的事情,但是我认为这不适用于不同类型的文件吗?
How can I convert these strings back to the original files? I've been trying things like this, but I don't think this will work with different types of files?
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($file)) |
Out-File C:\ID\document.$($extension)
任何人都可以向我提供一些有关如何执行此操作的想法吗?
Can anyone provide me some ideas on how to do this?
推荐答案
FromBase64String()
方法将base64编码的字符串转换为字节数组.您需要做的就是将该字节数组写回到文件中
The FromBase64String()
method converts a base64-encoded string to a byte array. All you need to do is write that byte array back to a file:
$b64 = 'AAAAAA...'
$filename = 'C:\path\to\file'
$bytes = [Convert]::FromBase64String($b64)
[IO.File]::WriteAllBytes($filename, $bytes)
这篇关于将base64字符串转换为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!