add file upload

This commit is contained in:
bee0005 2016-08-22 09:41:25 +00:00
parent 10c12d39e8
commit cbfa6976c7
13 changed files with 93 additions and 12 deletions

View File

@ -1,4 +1,5 @@
source 'https://rubygems.org'
gem 'carrierwave'
gem 'devise'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'

View File

@ -47,6 +47,12 @@ GEM
sass (>= 3.3.4)
builder (3.2.2)
byebug (8.2.4)
carrierwave (0.11.2)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
mimemagic (>= 0.3.0)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
@ -84,6 +90,7 @@ GEM
mime-types (3.0)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0221)
mimemagic (0.3.2)
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.11.2)
@ -164,6 +171,7 @@ PLATFORMS
DEPENDENCIES
bootstrap-sass (~> 3.3.6)
byebug
carrierwave
coffee-rails (~> 4.1.0)
devise
font-awesome-rails

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the volume controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,4 +1,4 @@
class VolumnController < ApplicationController
class VolumeController < ApplicationController
def info
@volumes = Array.new
volume = Hash.new
@ -27,4 +27,10 @@ class VolumnController < ApplicationController
return `sshpass -pakfm77 ssh -p 2222 root@124.63.216.174 gluster volume info`
end
def file_upload
file_name = params[:file]
uploader = AvatarUploader.new
uploader.store!(file_name)
redirect_to '/volume/info'
end
end

View File

@ -0,0 +1,2 @@
module VolumeHelper
end

View File

@ -0,0 +1,51 @@
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# 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
"/home/ubuntu/workspace/app/uploaders"
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:
# # ActionController::Base.helpers.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 :resize_to_fit => [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

Binary file not shown.

View File

@ -39,7 +39,7 @@
<li><a><i class="fa fa-edit"></i> Volume <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu" style="display: none">
<li><a href="/volumn/info">Info</a>
<li><a href="/volume/info">Info</a>
</li>
<li><a href="#">Create</a>
</li>

View File

@ -25,7 +25,7 @@
<%@volumes.each do |t|%>
<div class="col-md-12 col-sm-1 col-xs-12">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Infomation <small><%=t["Volume Name"]%></small></h2>
@ -49,7 +49,7 @@
<div class="x_content">
<div class="col-md-4 col-sm-1 col-xs-4">
<div class="col-md-4 col-sm-4 col-xs-4">
Type : <%=t["Type"]%> <br>
Volume ID : <%=t["Volume ID"]%> <br>
Status : <%=t["Status"]%> <br>
@ -61,14 +61,11 @@
performance.readdir-ahead : <%=t["performance.readdir-ahead"]%> <br>
</div>
<div class="col-md-8 col-sm-1 col-xs-8">
<div class="col-md-8 col-sm-8 col-xs-8">
<p>Drag multiple files to the box below for multi upload or click to select files. This is for demonstration purposes only, the files are not uploaded to any server.</p>
<form action="choices/form_upload.html" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px; ">
<button type="submit" style="position: absolute; right: 20px; bottom: -10px;">
Upload
</button>
<form action="/file_upload" method="post" enctype="multipart/form-data" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px; overflow:scroll;">
</form>
<br />
<br/>
</div>
</div>

View File

@ -0,0 +1,2 @@
# Allow non-ascii letters in uploaded filenames
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/

View File

@ -1,5 +1,5 @@
Rails.application.routes.draw do
get 'volumn/info'
get 'volume/info'
get 'home/index'
@ -12,7 +12,8 @@ Rails.application.routes.draw do
get 'index' => 'plainpage#index'
get 'volumn/info' => 'volumn#info'
get 'volume/info' => 'volume#info'
post 'file_upload' => 'volume#file_upload'
# Example of regular route:
# get 'products/:id' => 'catalog#view'

View File

@ -0,0 +1,7 @@
require 'test_helper'
class VolumeControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end