I am currently trying to understand the Cocoa Http Server regarding file transfer.Currently the form that is displayed when I connect to the http server via my browser is this. I select a file and it uploads fine. I am a bit confused as to what is called to handle the upload process.This is the form that is called.
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
</head>
<body>
<form action="upload.html" method="post" enctype="multipart/form-data" accept-charset="utf-8">
<input type="file" name="upload1"><br/>
<input type="file" name="upload2"><br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
I am confused about the form `action` part. From what I understand is that it calls `upload.html` This is the code for `upload.html`
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
</head>
<body>
%MyFiles%
</body>
</html>
My question is what is `%MyFiles%` ? What happens when a form posts to another html file ?
After doing a search for MyFiles in the entire project. I came up with this (this is the only place its being used). For convenience i have mentioned the objective C code below.
**My main question is what happens when a html form action posts to another html form ? In my case what is the other html form doing ?**
- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
{
HTTPLogTrace();
if ([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.html"])
{
// this method will generate response with links to uploaded file
NSMutableString* filesStr = [[NSMutableString alloc] init];
for( NSString* filePath in uploadedFiles ) {
//generate links
[filesStr appendFormat:@"<a href=\"%@\"> %@ </a><br/>",filePath, [filePath lastPathComponent]];
}
NSString* templatePath = [[config documentRoot] stringByAppendingPathComponent:@"upload.html"];
NSDictionary* replacementDict = [NSDictionary dictionaryWithObject:filesStr forKey:@"MyFiles"]; <---------This is where it is used again
// use dynamic file response to apply our links to response template
return [[HTTPDynamicFileResponse alloc] initWithFilePath:templatePath forConnection:self separator:@"%" replacementDictionary:replacementDict];
}
if( [method isEqualToString:@"GET"] && [path hasPrefix:@"/upload/"] ) {
// let download the uploaded files
return [[HTTPFileResponse alloc] initWithFilePath: [[config documentRoot] stringByAppendingString:path] forConnection:self];
}
return [super httpResponseForMethod:method URI:path];
}