Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
MOB-1988 Set MIMEType for item that upload by Share Extension
Browse files Browse the repository at this point in the history
  • Loading branch information
diego10bk committed Dec 1, 2015
1 parent 00a0f31 commit 01f9dae
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions share-extension/ShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -890,14 +890,28 @@ -(void) postMessage:(NSString *) message fileURL:(NSString *) fileURL fileName:(
NSRange rangeOfDocLink = [fileURL rangeOfString:@"jcr"];
NSString* docLink = [NSString stringWithFormat:@"/rest/%@", [fileURL substringFromIndex:rangeOfDocLink.location]];
title = [NSString stringWithFormat:@"Shared a document <a href=\"%@\">%@</a>\"", docLink, fileName];
templateParams = @{
@"DOCPATH":docPath,
@"MESSAGE":message,
@"DOCLINK":docLink,
@"WORKSPACE":defaultWorkspace,
@"REPOSITORY":currentRepository,
@"DOCNAME":fileName
};
NSString * mimeType = [self MIMETypeForFile:fileName];
if (mimeType && mimeType.length > 0) {
templateParams = @{
@"DOCPATH":docPath,
@"MESSAGE":message,
@"DOCLINK":docLink,
@"WORKSPACE":defaultWorkspace,
@"REPOSITORY":currentRepository,
@"DOCNAME":fileName,
@"mimeType":mimeType
};
} else {
templateParams = @{
@"DOCPATH":docPath,
@"MESSAGE":message,
@"DOCLINK":docLink,
@"WORKSPACE":defaultWorkspace,
@"REPOSITORY":currentRepository,
@"DOCNAME":fileName
};

}
}

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
Expand Down Expand Up @@ -1156,4 +1170,19 @@ - (UIImage *) rotateImage:(UIImage *)image {
return newImage;
}

-(NSString *) MIMETypeForFile:(NSString *)fileName {
NSRange lastPointRange = [fileName rangeOfString:@"." options:NSBackwardsSearch];
if (lastPointRange.location != NSNotFound) {
NSString * fileExtension = [fileName substringFromIndex:lastPointRange.location+1];
CFStringRef pathExtension = (__bridge CFStringRef)(fileExtension);
CFStringRef type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
CFRelease(pathExtension);
// The UTI can be converted to a mime type:
NSString *mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType);
return mimeType;
}

return nil;
}

@end

0 comments on commit 01f9dae

Please sign in to comment.