首页 > 解决方案 > 将base64字符串格式的图片上传到服务器

问题描述

我使用 CFURLCreateStringByAddingPercentEscapes 对 base64 图像字符串进行了编码:

(__bridge_transfer NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)imageString, NULL,CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))

这行得通。但是现在不推荐使用 CFURLCreateStringByAddingPercentEscapes,建议使用 stringByAddingPercentEncodingWithAllowedCharacters,我不确定允许使用什么字符集。我尝试了以下每个包含上述字符的集合,但没有一个有效:

@interface NSCharacterSet (NSURLUtilities)
+ (NSCharacterSet *)URLUserAllowedCharacterSet;
+ (NSCharacterSet *)URLPasswordAllowedCharacterSet;
+ (NSCharacterSet *)URLHostAllowedCharacterSet;
+ (NSCharacterSet *)URLPathAllowedCharacterSet;
+ (NSCharacterSet *)URLQueryAllowedCharacterSet;
+ (NSCharacterSet *)URLFragmentAllowedCharacterSet;
@end

任何帮助是极大的赞赏!

标签: iosobjective-cimage

解决方案


推荐阅读