-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3090d49
commit 5387079
Showing
16 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class UpyunImagesController < ApplicationController | ||
def new | ||
@upyun_image = UpyunImage.new | ||
end | ||
|
||
def show | ||
@img = UpyunImage.find(params[:id]) | ||
end | ||
|
||
def create | ||
file = params[:upyun_image][:asset] | ||
image = UpyunImage.new(params[:upyun_image]) | ||
image.filename = file.original_filename | ||
image.user = current_user | ||
if image.save | ||
redirect_to upyun_image_path(image) | ||
else | ||
redirect_to new_upyun_image_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# encoding: utf-8 | ||
class Settings < Settingslogic | ||
source "#{Rails.root}/config/settings.yml" | ||
namespace Rails.env | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class UpyunImage < ActiveRecord::Base | ||
belongs_to :user | ||
attr_accessible :asset | ||
|
||
mount_uploader :asset, UpyunImageUploader | ||
|
||
validates :asset, :content_type, :size, :filename, :presence => true | ||
validates_integrity_of :asset | ||
|
||
before_validation :set_metadata | ||
|
||
private | ||
def set_metadata | ||
self.content_type = asset.file.content_type | ||
self.size = asset.file.size | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'digest' | ||
require 'carrierwave/processing/mime_types' | ||
|
||
module UploaderHelper | ||
def store_dir | ||
"uploads/" | ||
end | ||
|
||
def cache_dir | ||
"/tmp" | ||
end | ||
|
||
def filename | ||
if original_filename.present? | ||
hashed_name = Digest::MD5.hexdigest(File.dirname(current_path))[5..15] | ||
"#{hashed_name}.#{file.extension}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# encoding: utf-8 | ||
|
||
class UpyunImageUploader < CarrierWave::Uploader::Base | ||
include UploaderHelper | ||
|
||
# Include RMagick or MiniMagick support: | ||
include CarrierWave::RMagick | ||
# include CarrierWave::MiniMagick | ||
|
||
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility: | ||
# include Sprockets::Helpers::RailsHelper | ||
# include Sprockets::Helpers::IsolatedHelper | ||
|
||
# Choose what kind of storage to use for this uploader: | ||
# storage :file | ||
# storage :fog | ||
storage :upyun | ||
|
||
self.upyun_username = Settings.upyun.operator_name | ||
self.upyun_password = Settings.upyun.operator_password | ||
self.upyun_bucket = Settings.upyun.bucket | ||
self.upyun_bucket_domain = Settings.upyun.bucket_domain | ||
|
||
process :resize_to_limit => [570, 0] | ||
# Override the directory where uploaded files will be stored. | ||
# This is a sensible default for uploaders that are meant to be mounted: | ||
#def store_dir | ||
#"public/uploads/" | ||
#end | ||
|
||
# Provide a default URL as a default if there hasn't been a file uploaded: | ||
# def default_url | ||
# # For Rails 3.1+ asset pipeline compatibility: | ||
# # asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) | ||
# | ||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_') | ||
# end | ||
|
||
# Process files as they are uploaded: | ||
# process :scale => [200, 300] | ||
# | ||
# def scale(width, height) | ||
# # do something | ||
# end | ||
|
||
# Create different versions of your uploaded files: | ||
# version :thumb do | ||
# process :scale => [50, 50] | ||
# end | ||
|
||
# Add a white list of extensions which are allowed to be uploaded. | ||
# For images you might use something like this: | ||
# def extension_white_list | ||
# %w(jpg jpeg gif png) | ||
# end | ||
|
||
# Override the filename of the uploaded files: | ||
# Avoid using model.id or version_name here, see uploader/store.rb for details. | ||
# def filename | ||
# "something.jpg" if original_filename | ||
# end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ | |
</div> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="container"> | ||
<%= form_for @upyun_image, :html => {:multipart => true} do |f| %> | ||
<p> | ||
<%= f.file_field :asset %> | ||
<br> | ||
<br> | ||
<%= f.submit "upload" %> | ||
</p> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="container"> | ||
<%= image_tag @img.asset_url.to_s %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
default: &default | ||
canonical_host: "www.example.com" | ||
system_email: "no-reply@example.com" | ||
memcached: | ||
servers: ["127.0.0.1:11211"] | ||
namespace: "example" | ||
upyun: | ||
switch: 'off' # to support file upload, change this to 'on' | ||
operator_name: '' | ||
operator_password: '' | ||
bucket: '' | ||
bucket_domain: '' | ||
|
||
production: | ||
<<: *default | ||
|
||
development: | ||
<<: *default | ||
|
||
test: | ||
<<: *default | ||
default_password: 'project_rabel' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateUpyunImages < ActiveRecord::Migration | ||
def change | ||
create_table :upyun_images do |t| | ||
t.integer :user_id | ||
t.string :asset | ||
t.integer :size | ||
t.string :content_type | ||
t.string :filename | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters