NSInputStream working with with local file, not with file pulled down from server
-
22-06-2021 - |
Question
Hey guys so I'm pulling down a yaml file from a web server. My NSInputStream
works great with local yaml files (using file://filename.yaml url scheme)
Here's the relevant code snippet:
NSInputStream * stream = [[NSInputStream alloc] initWithURL:yamlURL];
Where yaml url is something like http:// myip:8000/assets/test.yaml Opening in a browser just results in file download...
Any thoughts?
Solution
Is there anything you're doing with the *stream, After you initWithURL?
If you are taking the content from the InputStream inited with the local file, you would need to be creating a NSOutputStream to take the InputStream and redirect it to Safari. So I don't think just initWithURL: call with the url will tell you much, but the call to open the http:// url in safari will try to determine the content-type and try to output the file. But I don't think safari would be able to display the contents if it was a mulit-part mime yaml file.
OTHER TIPS
Im way too late for this, but i just solved this exact problem, so here goes:
As per the docs,
The NSStream class does not support connecting to a remote host on iOS.
As stupid as this sounds, initWithURL will only work for a local file. But theres an easy fix...
Full explanation and code sample from apple can be found here: https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/Streams/Articles/NetworkStreams.html#//apple_ref/doc/uid/20002277-BCIDFCDI