Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Convert base64string to url encoded string in Swift

$
0
0

My requirement:

I need to convert my base64 string to a base64 URL encoded string,

same like the conversion on this website: https://www.urlencoder.org/.

My code:

extension UIImage {    func toBase64URLEncodedString() -> String? {        guard let imageData = self.jpegData(compressionQuality: 1) else {            return nil        }        var base64String = imageData.base64EncodedString()        let allowedCharacterSet = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~")        // URL encode the Base64 string        return base64String.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet)   }}

It works for small strings, but when I use a large image base64 string, I encounter a strange issue. It only returns a few lines of data and ignores the rest.

My original base64 string (Its more than 100 lines):

enter image description here

My output: (It returns only 16 lines)

enter image description here


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>