Skip to content

Commit

Permalink
Merge pull request #1035 from rstylesoftlab/bugfix/file-name-from-hea…
Browse files Browse the repository at this point in the history
…der-on-ios

Adding the ability to get filename from header field
  • Loading branch information
EddyVerbruggen committed Jun 26, 2019
2 parents f7ccce5 + 7991b39 commit 4740df8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/ios/SocialSharing.m
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,23 @@ -(NSURL*)getFile: (NSString *)fileName {
if ([fileName hasPrefix:@"http"]) {
NSURL *url = [NSURL URLWithString:fileName];
NSData *fileData = [NSData dataWithContentsOfURL:url];
NSString *name = (NSString*)[[fileName componentsSeparatedByString: @"/"] lastObject];
file = [NSURL fileURLWithPath:[self storeInFile:[name componentsSeparatedByString: @"?"][0] fileData:fileData]];
NSURLRequest *request = [NSURLRequest requestWithURL: url];
NSHTTPURLResponse *response;
[NSURLConnection sendSynchronousRequest: request returningResponse: &response error: nil];
if ([response respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [response allHeaderFields];
NSLog([dictionary description]);
NSString *name = dictionary[@"Content-Disposition"];
if (name == nil){
NSString *name = (NSString*)[[fileName componentsSeparatedByString: @"/"] lastObject];
file = [NSURL fileURLWithPath:[self storeInFile:[name componentsSeparatedByString: @"?"][0] fileData:fileData]];
} else {
file = [NSURL fileURLWithPath:[self storeInFile:[[name componentsSeparatedByString:@"="] lastObject] fileData:fileData]];
}
} else {
NSString *name = (NSString*)[[fileName componentsSeparatedByString: @"/"] lastObject];
file = [NSURL fileURLWithPath:[self storeInFile:[name componentsSeparatedByString: @"?"][0] fileData:fileData]];
}
} else if ([fileName hasPrefix:@"www/"]) {
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *fullPath = [NSString stringWithFormat:@"%@/%@", bundlePath, fileName];
Expand Down

0 comments on commit 4740df8

Please sign in to comment.