使用rest-client上传文件
模型..
def self.upload_client_document(params)
client_document = self.new :uploaded_data => params[:Filedata],:client_id => params[:client_id],:document_name => self.default_document_name,:document_description => self.default_description_name
client_document.rename_document_name
client_document.save!
# RAILS_ROOT + client_document.public_filename This will return path to file like
# C:/projects/test_project/client_documents/0000/0012/A100-bal.csv
RestClient.post 'http://demo.testltd.com/V12345/search.aspx?username=test1&password=test2',
:upload => File.new(RAILS_ROOT + client_document.public_filename)
end
出现错误 Errno::ENOENT (没有这样的文件或目录 - C:/projects/test_project/client_documents/0000/0012/A100-bal.csv):
但是文件在文件夹中...
知道吗?这段代码有什么问题? 我需要为休息客户端修改什么吗?
Model ..
def self.upload_client_document(params)
client_document = self.new :uploaded_data => params[:Filedata],:client_id => params[:client_id],:document_name => self.default_document_name,:document_description => self.default_description_name
client_document.rename_document_name
client_document.save!
# RAILS_ROOT + client_document.public_filename This will return path to file like
# C:/projects/test_project/client_documents/0000/0012/A100-bal.csv
RestClient.post 'http://demo.testltd.com/V12345/search.aspx?username=test1&password=test2',
:upload => File.new(RAILS_ROOT + client_document.public_filename)
end
Getting error Errno::ENOENT (No such file or directory - C:/projects/test_project/client_documents/0000/0012/A100-bal.csv):
But file is there in the folder ...
Any idea ? What's problem with this code ?
Anything i need to modify for rest-client ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
File.new
创建一个文件。您需要File.read
另外:RAILS_ROOT 也已弃用。使用Rails.root
另外:不应该相信 client_document.public_filename 不包含某些内容,例如“../../”
...所以...
File.new
creates a file. You wantFile.read
Also: RAILS_ROOT is also deprecated. Use Rails.root
Also: client_document.public_filename should not be trusted to not include something e.g. "../../"
... so ...