Defect #13932

File upload does not work with Safari

Added by Frank Schwarz over 4 years ago. Updated over 3 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Attachments
Target version:2.4.6
Resolution:Fixed Affected version:2.3.1

Description

Tested with Safari 5.1.7 (Windows), but does also not work with Safari 6 (MacOS) Safari 5.1.9 (MacOS 10.6)

When you attach a file to an issue, a file with content

[object Object]

is created. The actual file is not uploaded.


Related issues

Related to Redmine - Defect #17151: File upload broken on Chrome 36 Closed
Related to Redmine - Defect #17581: Drag & Drop does not work with Safari 5.1 Closed

Associated revisions

Revision 13184
Added by Toshi MARUYAMA over 3 years ago

fix file upload does not work with Safari (#13932)

Contributed by Felix Schäfer.

Revision 13187
Added by Toshi MARUYAMA over 3 years ago

Merged r13184 from trunk to 2.5-stable (#13932)

Fix file upload does not work with Safari.

Contributed by Felix Schäfer.

Revision 13189
Added by Toshi MARUYAMA over 3 years ago

Merged r13184 from trunk to 2.4-stable (#13932)

Fix file upload does not work with Safari.

Contributed by Felix Schäfer.

Revision 13346
Added by Toshi MARUYAMA about 3 years ago

fix Drag & Drop does not work with Safari 5.1 (#17581, #13932)

Contributed by fred bregar.

Revision 13348
Added by Toshi MARUYAMA about 3 years ago

Merged r13346 from trunk to 2.5-stable (#17581, #13932)

fix Drag & Drop does not work with Safari 5.1.

Contributed by fred bregar.

Revision 13349
Added by Toshi MARUYAMA about 3 years ago

Merged r13346 from trunk to 2.4-stable (#17581, #13932)

fix Drag & Drop does not work with Safari 5.1.

Contributed by fred bregar.

History

#1 Updated by Filou Centrinov over 4 years ago

I can confirm that files won't uploaded via drag & drop on Safari 5.1.7 (Windows). See http://bugs.jquery.com/ticket/12182

#2 Updated by Mischa The Evil over 4 years ago

  • Status changed from New to Confirmed

#3 Updated by Frank Schwarz over 4 years ago

I have to correct myself: It does work with Safari 6, but it does not work with Safari 5.1.9 (MacOS 10.6)

#4 Updated by Jürgen Knödlseder over 4 years ago

Confirm. Run in exactly the same bug. Is someone already working on a fix?

#5 Updated by Toshi MARUYAMA over 4 years ago

  • Category changed from Files to Attachments

#6 Updated by Matt Andrews about 4 years ago

We've run into this one too Safari 5.1.7 on Windows 7 and Windows 8 - in Redmine version 2.3.3.

#7 Updated by Dave Martin about 4 years ago

Same here with Safari 5.1.10 (6534.59.10) on OS X 10.6.8 with Redmine 2.3.2.

#8 Updated by Felix Schäfer over 3 years ago

A client of Planio encountered the same issue on Mac OS 10.6 and Safari 5.1.9.

The problem is that Safari 5.1 only partially supports the API needed for this: it can pass files around and give the names of the files, but it cannot send the files as a binary stream directly. There are workarounds to emulate this, but the platform is pretty dated, so we instead chose to fallback to the normal (non-ajax) upload for Safari 5.1 (or any other browser that doesn't support the FileReader API, which is what is ultimately needed to achieve this the way it is currently implemented in Redmine):

diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js
index ab9f89a..a689c2e 100644
--- a/public/javascripts/attachments.js
+++ b/public/javascripts/attachments.js
@@ -117,7 +117,7 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
 function addInputFiles(inputEl) {
   var clearedFileInput = $(inputEl).clone().val('');

-  if (inputEl.files) {
+  if ('FileReader' in window && inputEl.files) {
     // upload files using ajax
     uploadAndAttachFiles(inputEl.files, inputEl);
     $(inputEl).remove();

The ajax/async upload function still works on modern browsers but is disabled for browsers that don't provide all required APIs for it.

#9 Updated by Jan from Planio www.plan.io over 3 years ago

  • Description updated (diff)

#10 Updated by Toshi MARUYAMA over 3 years ago

  • Related to Defect #17151: File upload broken on Chrome 36 added

#11 Updated by Toshi MARUYAMA over 3 years ago

  • Target version set to 2.4.6

#12 Updated by Toshi MARUYAMA over 3 years ago

  • Status changed from Confirmed to Closed
  • Resolution set to Fixed

Committed in trunk r13184, 2.5-stable r13187, and 2.4-stable r13189, thanks.

#13 Updated by fred bregar over 3 years ago

While this hack1 allows the user to click on the "choose" button for <input type=file> and select a file, you still cannot drag a file and upload. Safari 5.1 has no problems uploading File objects via ajax that are drag and dropped (I use it all the time.) The real culprit here is jQuery 1.8.3.

It's jQuery.extend which transforms the File object into a plain Object. $.extend is called from ajaxSetup, which is called from $.ajax on line 7644

re-attaching blob [object File] in beforeSend does the trick

diff --git a/attachments.js.original b/attachments.js
index 43803ba..b6d9eca 100644
--- a/attachments.js.original
+++ b/attachments.js
@@ -99,8 +99,10 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
   return $.ajax(uploadUrl, {
     type: 'POST',
     contentType: 'application/octet-stream',
-    beforeSend: function(jqXhr) {
+    beforeSend: function(jqXhr, settings) {
       jqXhr.setRequestHeader('Accept', 'application/js');
+      //attach proper File object 
+      settings.data = blob;
     },
     xhr: function() {
       var xhr = $.ajaxSettings.xhr();
@@ -117,7 +119,7 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
 function addInputFiles(inputEl) {
   var clearedFileInput = $(inputEl).clone().val('');

-  if ('FileReader' in window && inputEl.files) {
+  if (inputEl.files) {
     // upload files using ajax
     uploadAndAttachFiles(inputEl.files, inputEl);
     $(inputEl).remove();

1 FileReader API is not needed at all.

#14 Updated by Toshi MARUYAMA over 3 years ago

  • Related to Defect #17581: Drag & Drop does not work with Safari 5.1 added

Also available in: Atom PDF