You do:
let strBase64 = imageData.base64EncodedString(options: .lineLength64Characters)
and
let imageData = Data(base64Encoded: base64, options: .init(rawValue: 0))
So you added an option for the encoding, but not for the decoding? Is the default" decoding working then? No need to specify that there was a perticular option set?
Let's see the doc of lineLength64Characters
:
Set the maximum line length to 64 characters, after which a line ending is inserted.
Let's the the doc of available Data.Base64DecodingOptions
, especially .ignoreUnknownCharacters
:
Modify the decoding algorithm so that it ignores unknown non-Base-64 bytes, including line ending characters.
See?
Use .ignoreUnknownCharacters
while decoding instead of .init(rawValue:0)
(which by the way could be simplified with []
, or simply not putting the parameter since []
is its default value).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…