CocoaHTTPServer on iOS: configure the server so that the user can download NSData as a file

I want to make the following webpage using CocoaHTTPServer : there should be a link to download the file, but the source file must be an NSData object in memory.

As far as I see in the examples, there is an easy way to associate some iPhone file with a hyperlink. Is it possible to "bind" NSData ?

It would be very grateful for examples.

+6
source share
1 answer

All you have to do is return the HTTPDataResponse to your HTTPConnection subclass.

If you need an example, look at the CocoaHTTPServer example called DynamicServer and replace - httpResponseForMethod: URI: in MyHTTPConnection with something similar to the following:

 - (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path { // Before returning you can analyze the passed path argument and select the correct data object to return... return [[HTTPDataResponse alloc] initWithData:placeYourDataInstanceHere]; } 
+7
source

Source: https://habr.com/ru/post/927694/


All Articles