为什么yaml文件上传不起作用?我认为权限问题 [英] Why yaml file upload does not work? I think permission problems

查看:634
本文介绍了为什么yaml文件上传不起作用?我认为权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在config目录下加载一个由用户选择的yaml文件。
我有一个观点:$ b​​
$ b

 < h1>档案上载< / h1> 
< p>上传您的Yaml配置文件< / p>

< p style =color:green><%= flash [:notice]%>< / p>

<%= form_for:uploadFile,:html => {:multipart => true} do | f | %GT;

< label for =upload_file>选取档案:< / label>
<%= f.file_field:upload%>
<%= f.submit上传,:disable_with => '正在上传...'%>
<%end%>

我有一个控制器:

  class UploadController< ApplicationController 
def uploadFile
uploaded_io = params [:uploadFile] [:upload]
File.open(Rails.root.join('public',uploaded_io.original_filename),'w') |文件|
file.write(uploaded_io.read)
end

flash.now [:notice] =文件已成功上传

end
end

当用户选择文件并按下上传时,不在配置文件夹中。我能做什么?也许我应该使用import yaml并以某种方式加载它,怎么样?



这个日志说了这个:

 开始POST/ upload / uploadfilefor 127.0.0.1 at 2012-11-08 10:51:46 +0100 
UploadController处理#uploadfile as HTML
参数:{ UTF8=>中AOE, authenticity_token=> 中5FKgZJG4gKPCHXe8OqhFVZL0bu2X9zLR3sxd4ELBulA =,一个 uploadFile=> { 上传=>#< ActionDispatch :: HTTP :: UploadedFile的:0x3b03ad8 @ original_filename =newCases.yml,@ content_type =application / octet-stream,@ headers =Content-Disposition:form-data; name = \uploadFile [upload] \; filename = \\ \\newCases.yml \\r\\\
Content-Type:application / octet-stream \r\\\
,@tempfile =#< File:C:/ Users / Simo / AppData / Local / Temp / RackMultipart20121108-2664-tb7lxr>>}, 提交=> 中上传}
[1分[35mSetting负荷(0.0ms)[0米选择 设置 * FROM 设置 WHERE 设置。 。id=? LIMIT 1 [[id,1]]
在layouts / upload(0.0ms)内渲染upload / uploadfile.html.erb
在0ms内完成200 OK(查看:0.0ms | ActiveRecord:0.0ms )


解决方案

  .open(Rails.root.join('config',uploaded_io.original_filename),'wb +')do | file | 
file.write(uploaded_io.read)
end

/ p>

I would like to load in the config directory, a yaml file chosen by the user. I have a view:

<h1>File Upload</h1>
<p>Upload your Yaml Configuration File</p>

<p style="color: green"><%= flash[:notice] %></p>

<%= form_for :uploadFile, :html => { :multipart => true } do |f| %>

  <label for="upload_file">Select File:</label>
  <%= f.file_field :upload %>
  <%= f.submit "Upload", :disable_with => 'Uploading...' %>
<% end %>

and I have a controller:

class UploadController < ApplicationController
def uploadFile
    uploaded_io = params[:uploadFile][:upload]
    File.open(Rails.root.join('public', uploaded_io.original_filename), 'w') do |file|
        file.write(uploaded_io.read)
    end

    flash.now[:notice]="File has been uploaded successfully"

end
end

When the user selects the file and press "upload" nothing happens and the file is not in the config folder. What can I do? Maybe I should use "import yaml" and load it in a certain way, how?

The log said this:

Started POST "/upload/uploadfile" for 127.0.0.1 at 2012-11-08 10:51:46 +0100
Processing by UploadController#uploadfile as HTML
  Parameters: {"utf8"=>"âœ"",  "authenticity_token"=>"5FKgZJG4gKPCHXe8OqhFVZL0bu2X9zLR3sxd4ELBulA=", "uploadFile"=>{"upload"=>#<ActionDispatch::Http::UploadedFile:0x3b03ad8 @original_filename="newCases.yml", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"uploadFile[upload]\"; filename=\"newCases.yml\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:C:/Users/Simo/AppData/Local/Temp/RackMultipart20121108-2664-tb7lxr>>}, "commit"=>"Upload"}
  [1m[35mSetting Load (0.0ms)[0m  SELECT "settings".* FROM "settings" WHERE "settings"."id" = ? LIMIT 1  [["id", 1]]
  Rendered upload/uploadfile.html.erb within layouts/upload (0.0ms)
Completed 200 OK in 0ms (Views: 0.0ms | ActiveRecord: 0.0ms)

解决方案

File.open(Rails.root.join('config', uploaded_io.original_filename), 'wb+') do |file|
    file.write(uploaded_io.read)
end

Try this instead

这篇关于为什么yaml文件上传不起作用?我认为权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆