我正在使用 JPEGCAM 允许用户使用他们的网络摄像头拍摄个人资料照片。这会上传一个临时文件,如下所示:
def ajax_photo_upload
File.open(upload_path, 'w:ASCII-8BIT') do |f|
f.write request.raw_post
end
# @user.photo = File.open(upload_path)
@user.assign_attributes(
:photo => File.open(upload_path),
:orig_filename => "#{current_user.full_name}.jpg"
)
if @user.save
respond_to do |format|
.....
private
def upload_path # is used in upload and create
file_name = session[:session_id].to_s + '.jpg'
File.join(::Rails.root.to_s, 'public', 'temp', file_name)
end
安全删除此临时文件的最佳方法是什么?谢谢