我目前在尝试使用回形针上传视频时遇到一个奇怪的错误。配置正确,尝试链接目标文件时该过程失败。我看到视频属性确实可以成功存储,但是无法完成整个上传过程。我尝试了几种方法,并进行了大量研究以提出补救措施。似乎没有任何作用。
错误
irb(main):025:0>>> puts story.errors.inspect
puts story.errors.inspect
#<ActiveModel::Errors:0x000000000d184658 @base=#<Story id: nil, story_title: nil
user_id: nil, created_at: nil, updated_at
: nil, story_video_meta: nil, story_video_file_name: "06._complimennts___proc
edures_to_find_the_complime...", story_video_content_type: "video/mp4", story_vi
deo_file_size: 25043413, story_video_updated_at: "2018-08-31 03:47:52">, @messag
es={}, @details={}>
=> nil
irb(main):026:0>>> puts story.valid?
puts story.valid?
[paperclip] Trying to link C:/Users/DJ/AppData/Local/Temp/612d516926bed6276f129
f360380108520180830-2588-xid1kj.MP4 to C:/Users/DJ/AppData/Local/Temp/d99fb7c60
93b00699cd1d8c3ec77f0c920180831-2588-u08ej9.MP4
[paperclip] Link failed with File exists @ syserr_fail2_in - C:/Users/DJ/AppDat
a/Local/Temp/d99fb7c6093b00699cd1d8c3ec77f0c920180831-2588-u08ej9.MP4; copying l
ink C:/Users/DJ/AppData/Local/Temp/612d516926bed6276f129f360380108520180830-258
8-xid1kj.MP4 to C:/Users/DJ/AppData/Local/Temp/d99fb7c6093b00699cd1d8c3ec77f0c9
20180831-2588-u08ej9.MP4
Command :: file -b --mime "C:/Users/DJ/AppData/Local/Temp/d99fb7c6093b00699cd1d
8c3ec77f0c920180831-2588-u08ej9.MP4"
false
class StoriesController < ApplicationController
before_action :set_story, only: %i[show edit update destroy like unlike]
before_action :authenticate_user!
# GET /stories
# GET /stories.json
def index
@stories = current_user.stories.order(created_at: :desc).page(params[:page]).per(20)
end
# GET /stories/1
# GET /stories/1.json
def show
impressionist(@story)
end
# GET /stories/new
def new
@story = Story.new
end
# GET /stories/1/edit
def edit; end
# POST /stories
# POST /stories.json
def create
@story = current_user.stories.build(story_params)
respond_to do |format|
if @story.save
format.json {head :no_content}
format.js
else
format.json { render json: @story.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /stories/1
# PATCH/PUT /stories/1.json
def update
respond_to do |format|
if @story.update(story_params)
format.json { head :no_content }
format.js
else
format.json { render json: @story.errors, status: :unprocessable_entity }
end
end
end
# DELETE /stories/1
# DELETE /stories/1.json
def destroy
@story.destroy
respond_to do |format|
format.js
format.html { redirect_to stories_url }
format.json { head :no_content }
end
end
def like
@story.liked_by current_user
respond_to do |format|
format.html {redirect_to :back}
format.js
end
end
def unlike
@story.unliked_by current_user
respond_to do |format|
format.html {redirect_to :back}
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_story
@story = Story.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def story_params
params.require(:story).permit(:story_title, ::story_video, :story_video_meta)
end
end
story.rb
class Story < ApplicationRecord
include UniqueIdentifierLinksHelper
is_impressionable
belongs_to :user, optional: true
validates :story_title, presence: true, length: { minimum: 2, maximum: 100 }
validates :story_video, presence: true
has_attached_file :story_video, styles: {
medium: { geometry: '640x480', format: 'mp4' },
thumb: { geometry: '167x400#', format: 'png', time: 10 }
}, processors: [:transcoder], size: { in: 0..25.megabytes }
validates_attachment_content_type :story_video, content_type: /\Avideo\/.*\Z/
end