Parcourir la source

Image upload bugfix

Juergen 'eTM' Mangler il y a 2 ans
Parent
commit
74edfb20fb
2 fichiers modifiés avec 19 ajouts et 3 suppressions
  1. 6 2
      server/ustore.rb
  2. 13 1
      ui/js/Upload.js

+ 6 - 2
server/ustore.rb

@@ -94,15 +94,19 @@ class UploadData < Riddl::Implementation
     i = 0
     while i < @p.length do
 	    item = @p[i]
+      
       if(item != nil && item.name == "files[]")
         
-        #      puts item.inspect
+        #puts item.inspect
+        
+        #get filename from additional info as .filname is not alwys right?
+        readFilename = item.additional.inspect.to_s[/filename=\\"(.*?)\\"/m, 1]
         
         path = File.join(File.dirname(__dir__),'storage/', @r.drop(1).join("/"))
         FileUtils.mkdir_p(path)
         
         readFile = File.read(item.value.inspect.to_s[/Tempfile:(.*?)>/m, 1])
-        File.open(File.join(path, item.filename), 'wb') do |file|
+        File.open(File.join(path, readFilename), 'wb') do |file|
           file.write(readFile.to_s)
         end
         

+ 13 - 1
ui/js/Upload.js

@@ -105,8 +105,9 @@ function imageInit(){
 					e.preventDefault();
 					// gathering the form data
 					var ajaxData;
+          
 					
-					
+					var i = 0;
 					if( droppedFiles )
 					{
 						ajaxData = new FormData();
@@ -150,6 +151,17 @@ function imageInit(){
 						form.classList.remove( 'is-uploading' );
 						alert( 'Error. Please, try again!' );
 					};
+          
+          
+          
+          var object = {};
+ajaxData.forEach(function(value, key){
+    object[key] = value;
+});
+  console.log(JSON.stringify(object));
+
+
+
 					ajax.send( ajaxData );
           form.classList.remove( 'is-uploading' );
 					form.classList.remove( 'is-error', 'is-success' );