unable to serve files from the iOS file system. only from the app bundle.

175 views
Skip to first unread message

Ra Do

unread,
Jul 18, 2013, 5:44:42 PM7/18/13
to cocoaht...@googlegroups.com
Hello,

I've trying to setup a web server inside my iOS app to serve a single video.m4v file (for now).

If I specify the local application bundle as the document root:

NSString *webPath = [[NSBundle mainBundle] resourcePath];
[self.httpServer setDocumentRoot:webPath];

and manually add the video.m4v file to the app bundle, it works.

However, when I try to use the iOS file system as the document root it doesn't

    NSError* error = nil;
    NSArray *repositoryParentFolder = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
    NSArray *repositoryParentSubfoldersURL =  [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[repositoryParentFolder objectAtIndex:0] includingPropertiesForKeys:nil options:0 error:&error];
   
    for ( NSURL * obj in repositoryParentSubfoldersURL) {
        if ( [[obj lastPathComponent] isEqualToString:@"videoRoot"]) {
            NSURL *videoRoot = obj;
            NSLog (@"found videoRoot: %@", videoRoot);
            [self.httpServer setDocumentRoot:videoRoot.absoluteString];
            break;
        }
    }

All I see from the server is:

HTTP/1.1 404 Not Found Accept-Ranges: bytes Content-Length: 0
I am at a loss why this is happening.

The docRoot gets printed out as :

file://localhost/Users/me/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/E1A845D9-0B00-4BB9-84FA-68F2955998B5/Documents/videoRoot/

it exists, and the video.m4v file is definitely there. Also when I query the running server for self.httpServer.documentRoot is responds with the same directory.

Anyone sees something here that I'm doing wrong ?

Thank you!
Rad

Ra Do

unread,
Jul 18, 2013, 5:45:38 PM7/18/13
to cocoaht...@googlegroups.com
I forgot to mention, that all of this is happening in the iOS simulator. Not on an actual device.

camilo-otro

unread,
Dec 17, 2014, 5:49:07 PM12/17/14
to cocoaht...@googlegroups.com
Hi Rad Ben, 

Did you ever figure this out? I'm running into pretty much the same problem, I'm trying to use the documents folder of the application as the document root, but I cant seem to see any of the files through the started server.
Reply all
Reply to author
Forward
0 new messages