changeset 88:0f206bd4924f

Allows posting gzipped text.
author Edho Arief <edho@myconan.net>
date Tue, 06 Nov 2012 11:14:32 +0700
parents b245005ac9ac
children de4ce9ce1cc1
files app/controllers/pastes_controller.rb
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/pastes_controller.rb	Tue Nov 06 00:09:13 2012 +0700
+++ b/app/controllers/pastes_controller.rb	Tue Nov 06 11:14:32 2012 +0700
@@ -36,9 +36,17 @@
   # POST /pastes.txt
   def create
     @paste = Paste.new
-    if params[:paste] and not params[:paste][:paste].blank?
-      @paste.paste = params[:paste][:paste]
-      @paste.ip = request.remote_ip
+    if params[:paste]
+      if params[:paste][:paste_gzip_base64]
+        # 1. decode from base64
+        # 2. create StringIO from decoded string
+        # 3. unzip and read the stream
+        params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste][:paste_gzip_base64]))).read
+      end
+      unless params[:paste][:paste].blank?
+        @paste.paste = params[:paste][:paste]
+        @paste.ip = request.remote_ip
+      end
     end
 
     begin