ruby - Tempfile.new vs. File.open on Heroku -
i'm capturing/creating user entered text files app, attempting temporarily store them in heroku tmp directory, upload them cloud service such google drive.
in using tempfile can upload, when using file.open following error when attempting upload:
argumenterror (wrong number of arguments (1 0))
the error on call:
@client.upload_file_by_folder_id(save_path, @folder_id)
where @client session cloud service, save_path location of attached file upload , @folder_id folder should go into.
when use tempfile.new successful in doing so:
tempfile = tempfile.new([final_filename, '.txt'], rails.root.join('tmp','text-temp')) tempfile.binmode tempfile.write msgbody tempfile.close save_path = tempfile.path upload_file = @client.upload_file_by_folder_id(save_path, @folder_id) tempfile.unlink
file.open code is:
path = 'tmp/text-temp' filename = "#{final_filename}.txt" save_path = rails.root.join(path, filename) file.open(save_path, 'wb') |file| file.write(msgbody) file.close end upload_file = @client.upload_file_by_folder_id(save_path, @folder_id) file.delete(save_path)
could file.path string, , tempfile.path full path (but not string)? when put out each, identical.
i'd use file don't want change filename of existing attachments i'm uploading, whereas tempfile appends filename.
any , assistance appreciated. thanks!
in order work using file, needed set save_path string:
save_path.to_s
Comments
Post a Comment