Ver código fonte

HTTP async-uploading doesn't need another HTML document

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Romain Goyet 12 anos atrás
pai
commit
689fdb7aa4

+ 4 - 16
AspenProject/VLCHTTPUploaderController.m

@@ -93,7 +93,7 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
     // Add support for POST
     if ([method isEqualToString:@"POST"])
     {
-        if ([path isEqualToString:@"/upload.html"])
+        if ([path isEqualToString:@"/upload.json"])
         {
             return YES;
         }
@@ -108,7 +108,7 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
 
     // Inform HTTP server that we expect a body to accompany a POST request
 
-    if([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.html"]) {
+    if([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.json"]) {
         // here we need to make sure, boundary is set in header
         NSString* contentType = [request headerField:@"Content-Type"];
         NSUInteger paramsSeparator = [contentType rangeOfString:@";"].location;
@@ -151,21 +151,9 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
 - (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
 {
     HTTPLogTrace();
-
-    if ([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.html"])
+    if ([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.json"])
     {
-
-        // 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 = @{@"MyFiles": filesStr};
-        // use dynamic file response to apply our links to response template
-        return [[HTTPDynamicFileResponse alloc] initWithFilePath:templatePath forConnection:self separator:@"%" replacementDictionary:replacementDict];
+        return [[HTTPDataResponse alloc] initWithData:[@"\"OK\"" dataUsingEncoding:NSUTF8StringEncoding]];
     }
     if( [method isEqualToString:@"GET"] && [path hasPrefix:@"/upload/"] ) {
         // let download the uploaded files

+ 1 - 2
Resources/web/index.html

@@ -14,7 +14,6 @@
         $('#fileupload').fileupload({
           dataType: 'json',
           done: function (e, data) {
-            alert('DONE');
             $.each(data.result.files, function (index, file) {
               $('<p/>').text(file.name).appendTo(document.body);
             });
@@ -47,7 +46,7 @@
         <div class="bar" style="width: 0%;"></div>
       </div>
 
-      <input id="fileupload" type="file" name="files[]" data-url="upload.html" multiple>
+      <input id="fileupload" type="file" name="files[]" data-url="upload.json" multiple>
 
       <footer>
       <p>

+ 0 - 29
Resources/web/upload.html

@@ -1,29 +0,0 @@
-<!doctype html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <title>VLC for iOS File Uploader</title>
-    <link rel="stylesheet" href="reset.css">
-    <link rel="stylesheet" href="style.css">
-  </head>
-  <body>
-    <div class="container">
-      <header>
-      <div id="appIcon"></div>
-      <h1>VLC for iOS</h1>
-      </header>
-
-      <div>
-        <span id="uploadCompleted">Upload completed!</span>
-
-        <a href="index.html" id="uploadMore">Upload more Files</a>
-      </div>
-
-      <footer>
-      <p>
-      VLC for iOS is free, open-source software published by <a href="http://www.videolan.org" target="_blank">VideoLAN</a>. <br />Modification and redistribution is subject to $LICENSE and further rights reserved by the VideoLAN association.<br />You can find the sources to this application <a href="http://git.videolan.org/?p=vlc-ports/ios2.git;a=summary" target="_blank">online</a> and more information about licensing in the About dialog included within the app.
-      </p>
-      </footer>
-    </div>
-  </body>
-</html>

+ 0 - 4
VLC for iOS.xcodeproj/project.pbxproj

@@ -8,7 +8,6 @@
 
 /* Begin PBXBuildFile section */
 		29125E5617492219003F03E5 /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = 29125E5417492219003F03E5 /* index.html */; };
-		29125E5717492219003F03E5 /* upload.html in Resources */ = {isa = PBXBuildFile; fileRef = 29125E5517492219003F03E5 /* upload.html */; };
 		2915540117490A1E00B86CAD /* DDData.m in Sources */ = {isa = PBXBuildFile; fileRef = 291553EB17490A1E00B86CAD /* DDData.m */; };
 		2915540217490A1E00B86CAD /* DDNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 291553ED17490A1E00B86CAD /* DDNumber.m */; };
 		2915540317490A1E00B86CAD /* DDRange.m in Sources */ = {isa = PBXBuildFile; fileRef = 291553EF17490A1E00B86CAD /* DDRange.m */; };
@@ -263,7 +262,6 @@
 
 /* Begin PBXFileReference section */
 		29125E5417492219003F03E5 /* index.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index.html; sourceTree = "<group>"; };
-		29125E5517492219003F03E5 /* upload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = upload.html; sourceTree = "<group>"; };
 		291553EA17490A1E00B86CAD /* DDData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDData.h; sourceTree = "<group>"; };
 		291553EB17490A1E00B86CAD /* DDData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDData.m; sourceTree = "<group>"; };
 		291553EC17490A1E00B86CAD /* DDNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDNumber.h; sourceTree = "<group>"; };
@@ -681,7 +679,6 @@
 				7AC8629A1765DC560011611A /* reset.css */,
 				7AC8629B1765DC560011611A /* style.css */,
 				29125E5417492219003F03E5 /* index.html */,
-				29125E5517492219003F03E5 /* upload.html */,
 			);
 			path = web;
 			sourceTree = "<group>";
@@ -1416,7 +1413,6 @@
 				7D6BA1181748EFE100C0E203 /* VLCMenuViewController~ipad.xib in Resources */,
 				7D6BA11A174911C200C0E203 /* VLCMenuViewController~iphone.xib in Resources */,
 				29125E5617492219003F03E5 /* index.html in Resources */,
-				29125E5717492219003F03E5 /* upload.html in Resources */,
 				7D6B08C2174A831900A05173 /* vlc-xmas.png in Resources */,
 				7D6B08C3174A831900A05173 /* vlc-xmas@2x.png in Resources */,
 				7D6B08C7174A910500A05173 /* mediaUnread@2x.png in Resources */,