about summary refs log tree commit homepage
path: root/examples/rails_app-2.3.4/app
diff options
context:
space:
mode:
Diffstat (limited to 'examples/rails_app-2.3.4/app')
-rw-r--r--examples/rails_app-2.3.4/app/controllers/files_controller.rb24
-rw-r--r--examples/rails_app-2.3.4/app/views/files/pull.html.erb46
2 files changed, 63 insertions, 7 deletions
diff --git a/examples/rails_app-2.3.4/app/controllers/files_controller.rb b/examples/rails_app-2.3.4/app/controllers/files_controller.rb
index 004c13e..a0fdbb1 100644
--- a/examples/rails_app-2.3.4/app/controllers/files_controller.rb
+++ b/examples/rails_app-2.3.4/app/controllers/files_controller.rb
@@ -1,14 +1,15 @@
 require 'digest/sha1'
 
 class FilesController < ApplicationController
-  # used by streaming upload progress
+  # used by jQuery streaming upload progress
   def new
-    if request.post?
-      size, hexdigest = _read_sha1_size
-      msg = "Successfully upload file (size: #{size}, sha1: #{hexdigest})"
-      flash[:notice] = msg
-      redirect_to "/files/new"
-    end
+    _sha1_flash_self
+  end
+
+  # based on Ry Dahl's streaming AJAX pull:
+  # http://rubyforge.org/pipermail/mongrel-users/2007-July/003747.html
+  def pull
+    _sha1_flash_self
   end
 
   def index
@@ -51,4 +52,13 @@ private
     [ file.size, digest.hexdigest ]
   end
 
+  def _sha1_flash_self
+    if request.post?
+      size, hexdigest = _read_sha1_size
+      msg = "Successfully upload file (size: #{size}, sha1: #{hexdigest})"
+      flash[:notice] = msg
+      redirect_to :action => params[:action]
+    end
+  end
+
 end
diff --git a/examples/rails_app-2.3.4/app/views/files/pull.html.erb b/examples/rails_app-2.3.4/app/views/files/pull.html.erb
new file mode 100644
index 0000000..275704d
--- /dev/null
+++ b/examples/rails_app-2.3.4/app/views/files/pull.html.erb
@@ -0,0 +1,46 @@
+<html>
+  <head>
+<!-- http://rubyforge.org/pipermail/mongrel-users/2007-July/003747.html -->
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+    <title>streaming upload progress test</title>
+    <%= javascript_include_tag 'ajax_pull/prototype-1_5_1.js' %>
+    <%= javascript_include_tag 'ajax_pull/ajax_pull.js' %>
+    <%= javascript_include_tag 'ajax_pull/upload_progress.js' %>
+  </head>
+  <body>
+<%
+upid = "#{Time.now.to_i}.#{rand}"
+act = { :action => 'pull', :upload_id => upid }
+opt = {
+  :multipart => true,
+  :target => 'upload-target',
+  :onsubmit => "UploadProgress.begin('#{upid}')"
+}
+-%>
+
+    <% if flash[:notice] %>
+      <div class="notice"><%= flash[:notice] %></div>
+    <% end %>
+    <p><%= link_to "#{upid} (single)",
+          :action => 'status', :upload_id => upid %></p>
+    <p><%= link_to "#{upid} (stream)",
+           "/progress?long&upload_id=#{upid}" %></p>
+
+    <% form_tag(act, opt) do %>
+      <div><p><%= file_field_tag :data %></p></div>
+      <p><%= submit_tag :Upload %></p>
+    <% end %>
+
+    <p>Below is the results <code>div</code></p>
+    <div id="results">(nothing)</div>
+
+    <p>Below is the progress bar <code>div</code></p>
+    <div id="progress-bar"></div>
+
+    <p>Below is the debug list</p>
+    <ol id="debug"></ol>
+
+    <iframe id="upload-target" name="upload-target" src="about:blank"></iframe>
+
+  </body>
+</html>