diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d1a9895..9c931af 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -197,16 +197,21 @@ def handle_form_submit(params, view) @post = post_from_form(params) if params[:commit] == "Upload Selected Image" if !(params[:post][:pic].nil?) - @image = Image.new - @image.blob.attach params[:post][:pic] - @image.save - file_ext = path_for(@image.blob).split(".").last - if (file_ext == "mp3") - @post.content += process_new_audio(@image) - elsif (file_ext == "mp4") - @post.content += process_new_video(@image) - else - @post.content += process_new_image(@image) + begin + @image = Image.new + @image.blob.attach params[:post][:pic] + @image.save + file_ext = path_for(@image.blob).split(".").last + if (file_ext == "mp3") + @post.content += process_new_audio(@image) + elsif ["mp4","mov"].include? file_ext + @post.content += process_new_video(@image) + else + @post.content += process_new_image(@image) + end + rescue => e + @image.destroy + flash.now[:alert] = "Error uploading file: #{e}" end else # attachment does not exist flash.now[:alert] = "You did not choose a file to upload" diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb index b6d6db1..360383f 100644 --- a/app/views/posts/_form.html.erb +++ b/app/views/posts/_form.html.erb @@ -3,7 +3,7 @@ <%= form.date_field :date, :style => 'display:inline;', :value => @post.datetime.strftime("%Y-%m-%d"), type: (@show_date ? :date : :hidden) %> <%= form.time_field :time, :style => 'display:inline;', :value => @post.datetime.strftime("%H:%M"), type: (@show_date ? :time : :hidden) %> <%= form.text_area :content, :rows => 10, :dir => "auto", :style => 'display:block;width:100%;', :oninput => "doRender()", :value => @post.content %> - <%= form.file_field :pic, :accept => "image/*,.mp4,.mp3", :style => "display:inline;" %> + <%= form.file_field :pic, :accept => "image/*,.mp4,.mov,.mp3", :style => "display:inline;" %> <%= form.submit :value => "Upload Selected Image", data: {disable_with: "Upload Selected Image"}, :style => "display:inline;" %> <%= form.submit :value => "Save Post", :style => "display:block;" %> <% end %>