myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2304] trunk/lib/rest.rb: added ability to submit


From: noreply
Subject: [myexperiment-hackers] [2304] trunk/lib/rest.rb: added ability to submit svg files during workflow upload
Date: Wed, 25 Nov 2009 10:43:59 -0500 (EST)

Revision
2304
Author
dgc
Date
2009-11-25 10:43:59 -0500 (Wed, 25 Nov 2009)

Log Message

added ability to submit svg files during workflow upload

Modified Paths

Diff

Modified: trunk/lib/rest.rb (2303 => 2304)


--- trunk/lib/rest.rb	2009-11-24 17:08:32 UTC (rev 2303)
+++ trunk/lib/rest.rb	2009-11-25 15:43:59 UTC (rev 2304)
@@ -877,6 +877,7 @@
     content_type     = parse_element(data, :text,   '/workflow/content-type')
     content          = parse_element(data, :binary, '/workflow/content')
     preview          = parse_element(data, :binary, '/workflow/preview')
+    svg              = parse_element(data, :text,   '/workflow/svg')
     revision_comment = parse_element(data, :text,   '/workflow/revision-comment')
 
     permissions  = data.find_first('/workflow/permissions')
@@ -939,6 +940,25 @@
       image.close
     end
 
+    if svg.nil? and content
+      metadata = Workflow.extract_metadata(:type => ob.content_type.title, :data ="" content)
+      svg = metadata["image"].read if metadata["image"]
+    end
+
+    if svg
+
+      svg_file = Tempfile.new('image')
+      svg_file.write(svg)
+      svg_file.rewind
+
+      svg_file.extend FileUpload
+      svg_file.original_filename = 'svg'
+      
+      ob.svg = svg_file
+
+      svg_file.close
+    end
+
     success = if (action == 'create' and query['id'])
       ob.save_as_new_version(revision_comment)
     else
@@ -1522,8 +1542,19 @@
 def parse_element(doc, kind, query)
   case kind
     when :text
-      el = doc.find_first("#{query}/text()")
-      return el.to_s if el
+      if doc.find_first(query)
+
+        enc = doc.find_first(query)['encoding']
+        el  = doc.find_first("#{query}/text()")
+
+        if el
+          if enc == 'base64'
+            return Base64::decode64(el.to_s)
+          else
+            return el.to_s
+          end
+        end
+      end
     when :binary
       el = doc.find_first("#{query}/text()")
       return Base64::decode64(el.to_s) if el

reply via email to

[Prev in Thread] Current Thread [Next in Thread]