Skip to content

Commit

Permalink
Merge pull request waynehoover#87 from Hengjie/master
Browse files Browse the repository at this point in the history
Fix IE9 issue with timestamp/unique_id
  • Loading branch information
waynehoover committed May 21, 2013
2 parents 9b31b75 + 3ecc124 commit c8b0df2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/assets/javascripts/s3_direct_upload.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ $.fn.S3Uploader = (options) ->
name: "content-type"
value: fileType

key = $uploadForm.data("key").replace('{timestamp}', new Date().getTime()).replace('{unique_id}', @files[0].unique_id)

# substitute upload timestamp and unique_id into key
key = data[1].value.replace('{timestamp}', new Date().getTime()).replace('{unique_id}', @files[0].unique_id)
data[1].value = settings.path + key

# IE <= 9 doesn't have XHR2 hence it can't use formData
# replace 'key' field to submit form
unless 'FormData' of window
$uploadForm.find("input[name='key']").val(settings.path + key)
data

build_content_object = ($uploadForm, file, result) ->
Expand All @@ -111,7 +117,7 @@ $.fn.S3Uploader = (options) ->
content.filepath = $('<a />').attr('href', content.url)[0].pathname
else # IE <= 9 return a null result object so we use the file object instead
domain = $uploadForm.attr('action')
content.filepath = settings.path + $uploadForm.find('input[name=key]').val().replace('/${filename}', '')
content.filepath = $uploadForm.find('input[name=key]').val().replace('/${filename}', '')
content.url = domain + content.filepath + '/' + encodeURIComponent(file.name)

content.filename = file.name
Expand All @@ -131,6 +137,9 @@ $.fn.S3Uploader = (options) ->

#public methods
@initialize = ->
# Save key for IE9 Fix
$uploadForm.data("key", $uploadForm.find("input[name='key']").val())

setUploadForm()
this

Expand Down

0 comments on commit c8b0df2

Please sign in to comment.