开发者

How to create an instance of an uploaded file programmatically in rails

开发者 https://www.devze.com 2022-12-14 16:09 出处:网络
I want to create an instance of \"uploaded_file = ActionController::UploadedTempfile\"from a File.new(\"path/to/file\"), and then go on to do processing on \"uploaded_file\" like so:

I want to create an instance of "uploaded_file = ActionController::UploadedTempfile" from a File.new("path/to/file"), and then go on to do processing on "uploaded_file" like so:

uploaded_file = ActionController::UploadedTempfile.new(File.new "path/to/file").

But for everything to work correctly, I need to set it so that uploaded_file.original_filename method and uploaded_file.content_type method开发者_运维知识库s work correctly. How do i assign its variables so that it works?


you can set content_type by simply assigning, and to set original_filename, you can do

obj.instance_variable_set "@original_filename", "whatyouwant"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号