Skip to content

Commit

Permalink
Add support for uploading MOV video files
Browse files Browse the repository at this point in the history
  • Loading branch information
mawise committed Dec 30, 2024
1 parent 90a3b93 commit 7400a8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down

0 comments on commit 7400a8e

Please sign in to comment.