Base64 resource support all kinds of base64
This commit is contained in:
parent
d9c53f328b
commit
2c399e6a64
@ -37,18 +37,13 @@ class DoricBase64Resource extends DoricResource {
|
|||||||
@Override
|
@Override
|
||||||
public AsyncResult<byte[]> fetchRaw() {
|
public AsyncResult<byte[]> fetchRaw() {
|
||||||
AsyncResult<byte[]> ret = new AsyncResult<>();
|
AsyncResult<byte[]> ret = new AsyncResult<>();
|
||||||
Pair<String, String> result = DoricUtils.translateBase64(identifier);
|
String[] split = identifier.split(",");
|
||||||
if (result != null) {
|
if (split.length > 0) {
|
||||||
String imageType = result.first;
|
try {
|
||||||
String base64 = result.second;
|
byte[] data = Base64.decode(split[split.length - 1], Base64.DEFAULT);
|
||||||
|
ret.setResult(data);
|
||||||
if (!TextUtils.isEmpty(imageType) && !TextUtils.isEmpty(base64)) {
|
} catch (Exception e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
byte[] data = Base64.decode(base64, Base64.DEFAULT);
|
|
||||||
ret.setResult(data);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret.setError(new Error("Base64 format error"));
|
ret.setError(new Error("Base64 format error"));
|
||||||
|
@ -23,10 +23,7 @@
|
|||||||
@implementation DoricBase64Resource
|
@implementation DoricBase64Resource
|
||||||
- (DoricAsyncResult <NSData *> *)fetchRaw {
|
- (DoricAsyncResult <NSData *> *)fetchRaw {
|
||||||
DoricAsyncResult *result = [DoricAsyncResult new];
|
DoricAsyncResult *result = [DoricAsyncResult new];
|
||||||
NSString *inString = nil;
|
NSString *inString = [self.identifier componentsSeparatedByString:@","].lastObject;
|
||||||
if ([self.identifier hasPrefix:@"data:image"]) {
|
|
||||||
inString = [self.identifier componentsSeparatedByString:@","].lastObject;
|
|
||||||
}
|
|
||||||
NSData *data = [[NSData alloc] initWithBase64EncodedString:inString
|
NSData *data = [[NSData alloc] initWithBase64EncodedString:inString
|
||||||
options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
||||||
[result setupResult:data];
|
[result setupResult:data];
|
||||||
|
Reference in New Issue
Block a user