Skip to content

Commit

Permalink
Added svg images and Content-Type is now set on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Glen committed Mar 12, 2015
1 parent 10c7e46 commit 538c483
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/assets/javascripts/smithy/assets.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jQuery ->
file = data.files[0]
if types.test(file.type) || types.test(file.name)
data.context = $(tmpl("template-upload", file))
$('#fileupload').append(data.context)
$(this).find('#Content-Type').val(file.type)
$(this).append(data.context)
data.submit()
else
alert("#{file.name} is not a gif, jpeg, png, svg or pdf file")
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/smithy/upload_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def fields
:policy => policy,
:signature => signature,
"AWSAccessKeyId" => @options[:aws_access_key_id],
"Content-Type" => nil
}
end

Expand All @@ -86,6 +87,7 @@ def policy_data
conditions: [
["starts-with", "$utf8", ""],
["starts-with", "$key", ""],
["starts-with", "$Content-Type", ""],
["content-length-range", 0, @options[:max_file_size]],
{bucket: @options[:bucket]},
{acl: @options[:acl]}
Expand Down
2 changes: 2 additions & 0 deletions app/models/smithy/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def file_type
case ext
when 'jpg', 'jpeg', 'gif', 'png'
:image
when 'svg', 'svgz'
:direct_image
when 'pdf'
:pdf
when 'doc', 'docx'
Expand Down
2 changes: 2 additions & 0 deletions app/views/smithy/assets/_asset.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<%= link_to asset.file.remote_url do %>
<% if asset.file_type == :image %>
<%= image_tag asset.file.thumb("340x226#").url, width: 170, height: 114, alt: '' %>
<% elsif asset.file_type == :direct_image %>
<%= image_tag asset.file.remote_url, width: 170, alt: '' %>
<% else %>
<div style="width:170px;height:78px;padding-top:36px;text-align:center;"><%= image_tag file_type_icon(asset), alt: '' %></div>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/smithy/assets/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<%= link_to @asset.file.remote_url do %>
<% if @asset.file_type == :image %>
<img src="<%= @asset.file.thumb("300x300").url %>" alt="">
<% elsif @asset.file_type == :direct_image %>
<%= image_tag @asset.file.remote_url, width: 300, alt: '' %>
<% else %>
<%= image_tag file_type_icon(@asset), alt: '' %>
<% end %>
Expand Down

0 comments on commit 538c483

Please sign in to comment.