I am trying to implement an api for uploading a photo. The input json is {"Photo":"base64stringValue"}
. The code used to convert the uiimage to base64string is
我正在尝试使用api上传照片。输入json是{“Photo”:“base64stringValue”}。用于将uiimage转换为base64string的代码是
let imageData = UIImageJPEGRepresentation(image, 0.9)
let imageStr = imageData?.base64EncodedString(options: .lineLength64Characters)
the conversion is successful. When I convert the imageStr
obtained to an image I am able to obtain the correct image. However, on passing this string to {"Photo":imageStr}
I get an error saying
转换成功。当我将获得的imageStr转换为图像时,我能够获得正确的图像。但是,在将此字符串传递给{“Photo”:imageStr}时,我收到错误消息
SUCCESS: {
Message = "The request is invalid.";
ModelState = {
model = (
"An error has occurred."
);
};
On checking i found that base64string now contains random \r\
values inserted in between. Is this an issue? if yes, how can it be resolved?
在检查时我发现base64string现在包含插入其间的随机\ r \ _值。这是一个问题吗?如果是的话,怎么解决?
1 个解决方案
#1
0
Objective C code i had used:
我用过的目标C代码:
NSData *imgData4 = UIImageJPEGRepresentation(image, 0);
NSString *base64Encoded = [imgData4 base64EncodedStringWithOptions:0];
#1
0
Objective C code i had used:
我用过的目标C代码:
NSData *imgData4 = UIImageJPEGRepresentation(image, 0);
NSString *base64Encoded = [imgData4 base64EncodedStringWithOptions:0];