Base64 resource support all kinds of base64

This commit is contained in:
pengfei.zhou 2022-02-17 11:45:28 +08:00 committed by osborn
parent d9c53f328b
commit 2c399e6a64
2 changed files with 8 additions and 16 deletions

View File

@ -37,19 +37,14 @@ class DoricBase64Resource extends DoricResource {
@Override
public AsyncResult<byte[]> fetchRaw() {
AsyncResult<byte[]> ret = new AsyncResult<>();
Pair<String, String> result = DoricUtils.translateBase64(identifier);
if (result != null) {
String imageType = result.first;
String base64 = result.second;
if (!TextUtils.isEmpty(imageType) && !TextUtils.isEmpty(base64)) {
String[] split = identifier.split(",");
if (split.length > 0) {
try {
byte[] data = Base64.decode(base64, Base64.DEFAULT);
byte[] data = Base64.decode(split[split.length - 1], Base64.DEFAULT);
ret.setResult(data);
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
ret.setError(new Error("Base64 format error"));
}

View File

@ -23,10 +23,7 @@
@implementation DoricBase64Resource
- (DoricAsyncResult <NSData *> *)fetchRaw {
DoricAsyncResult *result = [DoricAsyncResult new];
NSString *inString = nil;
if ([self.identifier hasPrefix:@"data:image"]) {
inString = [self.identifier componentsSeparatedByString:@","].lastObject;
}
NSString *inString = [self.identifier componentsSeparatedByString:@","].lastObject;
NSData *data = [[NSData alloc] initWithBase64EncodedString:inString
options:NSDataBase64DecodingIgnoreUnknownCharacters];
[result setupResult:data];