Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use attachments with data URLs #1

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions BodymovinQL/BodymovinPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ - (NSDictionary *) previewProperties {
//append animation assets
if (attachmentsCount > 1) {
for (NSString *assetsFile in _assets) {
if ([assetsFile hasPrefix:@"data:"] && attachData(assetsFile, attachments)) {
continue;
}
attach(_fileURL, attachments, [self mimeTypeForFileAtPath:assetsFile], assetsFile);
}
}
Expand All @@ -118,4 +121,16 @@ static void attach(NSURL *attachURL, NSMutableDictionary* attachments, NSString*
NSDictionary* attachment = [NSMutableDictionary dictionaryWithObjectsAndKeys:type, (NSString *)kQLPreviewPropertyMIMETypeKey, data, (NSString *)kQLPreviewPropertyAttachmentDataKey, nil];
[attachments setObject:attachment forKey:fileName];
}

static BOOL attachData(NSString *dataURL, NSMutableDictionary* attachments)
{
NSRange semicolonRange = [dataURL rangeOfString:@";"];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:dataURL]];
if (semicolonRange.location == NSNotFound || data == nil)
return NO;
NSString *type = [dataURL substringWithRange:NSMakeRange(5, semicolonRange.location-5)];
NSDictionary* attachment = [NSMutableDictionary dictionaryWithObjectsAndKeys:type, (NSString *)kQLPreviewPropertyMIMETypeKey, data, (NSString *)kQLPreviewPropertyAttachmentDataKey, nil];
[attachments setObject:attachment forKey:dataURL];
return YES;
}
@end