ios - 将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
任何帮助是极大的赞赏!
解决方案
推荐阅读
- python - django,如何处理带有外键的modelForm?
- eclipse - 升级 Eclipse RCP 应用程序
- javascript - Leaflet.js:maxZoom 和 minZoom 不起作用
- c# - 如何在 Asp.Net Core 3.0 WebAPI 中启用 CORS
- javascript - 元素的类名在循环中未定义
- 的子节点
- openid - ADFS 2019 登录页面未重定向到我的应用程序
- amazon-web-services - 如何在仪表板中清除 aws 批处理作业历史记录
- python-3.x - 在熊猫中将几个替换语句组合成一个
- java - java - 在构造函数中创建时,如何在java中关闭ExecuterService..?
- java - 如何使用java Process知道文件是否关闭