Skip to content

Commit 7400a8e

Browse files
committed
Add support for uploading MOV video files
1 parent 90a3b93 commit 7400a8e

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

app/controllers/posts_controller.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,21 @@ def handle_form_submit(params, view)
197197
@post = post_from_form(params)
198198
if params[:commit] == "Upload Selected Image"
199199
if !(params[:post][:pic].nil?)
200-
@image = Image.new
201-
@image.blob.attach params[:post][:pic]
202-
@image.save
203-
file_ext = path_for(@image.blob).split(".").last
204-
if (file_ext == "mp3")
205-
@post.content += process_new_audio(@image)
206-
elsif (file_ext == "mp4")
207-
@post.content += process_new_video(@image)
208-
else
209-
@post.content += process_new_image(@image)
200+
begin
201+
@image = Image.new
202+
@image.blob.attach params[:post][:pic]
203+
@image.save
204+
file_ext = path_for(@image.blob).split(".").last
205+
if (file_ext == "mp3")
206+
@post.content += process_new_audio(@image)
207+
elsif ["mp4","mov"].include? file_ext
208+
@post.content += process_new_video(@image)
209+
else
210+
@post.content += process_new_image(@image)
211+
end
212+
rescue => e
213+
@image.destroy
214+
flash.now[:alert] = "Error uploading file: #{e}"
210215
end
211216
else # attachment does not exist
212217
flash.now[:alert] = "You did not choose a file to upload"

app/views/posts/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<%= form.date_field :date, :style => 'display:inline;', :value => @post.datetime.strftime("%Y-%m-%d"), type: (@show_date ? :date : :hidden) %>
44
<%= form.time_field :time, :style => 'display:inline;', :value => @post.datetime.strftime("%H:%M"), type: (@show_date ? :time : :hidden) %>
55
<%= form.text_area :content, :rows => 10, :dir => "auto", :style => 'display:block;width:100%;', :oninput => "doRender()", :value => @post.content %>
6-
<%= form.file_field :pic, :accept => "image/*,.mp4,.mp3", :style => "display:inline;" %>
6+
<%= form.file_field :pic, :accept => "image/*,.mp4,.mov,.mp3", :style => "display:inline;" %>
77
<%= form.submit :value => "Upload Selected Image", data: {disable_with: "Upload Selected Image"}, :style => "display:inline;" %>
88
<%= form.submit :value => "Save Post", :style => "display:block;" %>
99
<% end %>

0 commit comments

Comments
 (0)