lundi 6 avril 2015

Understanding file upload form by Cocoa Http Server

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.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://ift.tt/nYkKzf">
<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



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://ift.tt/nYkKzf">
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
</head>
<body>
%MyFiles%
</body>
</html>


My question is what is %MyFiles% ? After doing a search for MyFiles in the entire project. I came up with this (this is the only place its being used)



- (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"];
// 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];
}


What is happening here ?





Aucun commentaire:

Enregistrer un commentaire