Commit bdc93696c85f960c784765f634eaa12c3ed17b62

Authored by Antonio Terceiro
1 parent 4999c5de

Return text/plain from the upload instead

The problem is that file uploads cannot be done via real AJAX, so the
jQuery form plugin creates a hidden iframe and does the upload there.
This approach has limitations, and among them is not being able to send
proper JSON responses for file uploads.

See http://jquery.malsup.com/form/#file-upload
app/controllers/my_profile/cms_controller.rb
... ... @@ -303,7 +303,7 @@ class CmsController < MyProfileController
303 303 files_uploaded << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => parent) unless file == ''
304 304 end
305 305 end
306   - render :text => article_list_to_json(files_uploaded), :content_type => 'application/json'
  306 + render :text => article_list_to_json(files_uploaded), :content_type => 'text/plain'
307 307 end
308 308  
309 309 protected
... ...
test/functional/cms_controller_test.rb
... ... @@ -1496,7 +1496,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
1496 1496 should 'upload media by AJAX' do
1497 1497 post :media_upload, :profile => profile.identifier, :file1 => fixture_file_upload('/files/test.txt', 'text/plain'), :file2 => fixture_file_upload('/files/rails.png', 'image/png'), :file3 => ''
1498 1498 assert_match 'test.txt', @response.body
1499   - assert_equal 'application/json', @response.content_type
  1499 + assert_equal 'text/plain', @response.content_type
1500 1500  
1501 1501 data = parse_json_response
1502 1502  
... ... @@ -1523,7 +1523,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
1523 1523  
1524 1524 post :media_upload, :profile => profile.identifier, :media_listing => true, :file1 => fixture_file_upload('files/rails.png', 'image/png'), :file2 => fixture_file_upload('/files/test.txt', 'text/plain')
1525 1525  
1526   - assert_equal 'application/json', @response.content_type
  1526 + assert_equal 'text/plain', @response.content_type
1527 1527 data = parse_json_response
1528 1528  
1529 1529 assert_equal 'rails.png', data[0]['title']
... ...