railsAPI接收Base64文件
程序员文章站
2022-07-12 20:18:39
...
tmp_dir = "tmp/pdf/" FileUtils.mkdir(tmp_dir) unless File.exists?(tmp_dir) pdf_tmp_path = "#{tmp_dir}#{file_name}.pdf" File.open(pdf_tmp_path, 'wb') { |f| f.write(Base64.decode64(pdf_base64_code)) } attachment = Attachment.new(attachment_entity_type: finance_bill.class.name, attachment_entity_id: finance_bill.id) File.open(pdf_tmp_path) do |f| attachment.path = f end attachment.save
# 导出txt价格 def pubchem_txt head = %w{smiles PUBCHEM_EXT_DATASOURCE_REGID PUBCHEM_SUBSTANCE_SYNONYM PUBCHEM_EXT_SUBSTANCE_URL PUBCHEM_EXT_DATASOURCE_URL PUBCHEM_GENERIC _REGISTRY_NAME} local_file_d = File.join("") local_file_d << head.join("\t") + "\n" chemical_ids = StockChemicalPriceRecord.select(:chemical_id).joins("left join ban_chemicals b on b.chemical_id = stock_chemical_price_records.chemical_id ").where('b.id is null ').group(:chemical_id) chemicals = Chemical.where(id:chemical_ids) chemicals.each do |chemical| data_list = ["#{chemical.smiles}","#{chemical.catalog_no}","#{chemical.name}","http://www.ichemical.com/products/#{chemical.cas}.html","http://www.ichemical.com","#{chemical.cas}"] local_file_d << data_list.join("\t") + "\n" end send_data( local_file_d, filename: "pubchem Package Info-#{rand(99999)}.txt", type: "application/txt", disposition: "attachment" ) end
上一篇: 一些常用加密方式
推荐阅读
-
canvas压缩图片转换成base64格式输出文件流
-
android通过蓝牙接收文件打开时无法自动选择合适的应用程序
-
vue-cli+axios实现文件上传下载功能(下载接收后台返回文件流)
-
JavaScript Base64 作为文件上传的实例代码解析
-
Android中发送Http请求(包括文件上传、servlet接收)的实例代码
-
Nodejs如何把接收图片base64格式保存为文件存储到服务器上
-
Nodejs把接收图片base64格式保存为文件存储到服务器上
-
javascript上传文件后台接收代码实现教程
-
Android上传文件到Web服务器 PHP接收文件
-
使用base64编码把背景添加到CSS文件中