Swift Base64 Format

左心房为你撑大大i 提交于 2019-12-31 05:27:06

问题


On this website, for example when you drop in an image, it is turned into a proper base64 format: http://base64image.org/

In my Swift app, here is what I have to generate a base64 string from an image:

let image_Data = UIImagePNGRepresentation(default_image)
let base64String = image_Data!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)

This gives me something similar, but it has spaces and line breaks. How do I get an output just like the output from the website above?


回答1:


let image_Data = UIImagePNGRepresentation(default_image)
let base64String = image_Data!.base64EncodedStringWithOptions([]) // Don't ask for line breaks

If you remove the request for line breaks, does it match what you're expecting?



来源:https://stackoverflow.com/questions/34406024/swift-base64-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!