下载的Google文档在Ruby的路径在哪里?
Where is the path for the downloaded Google document in Ruby?
我正在尝试使用 Ruby 下载 google 文档文件。我找不到下载文件的路径。我在 ruby 中使用 'export_file' 方法命令如下:
file_id = 'xxxxxx'
内容 = google_drive.export_file(file_id,
'application/pdf',
download_dest: StringIO.new)
控制台响应如下
正在写入块(1389 字节)
写入块(1389 字节)
写入块(1389 字节)
写入块(1389 字节)
写入块(896 字节)
写入块(2 个字节)
写入块(1234 字节)
成功 - #
=>#
似乎下载了一些东西,但是在 rails 中,我找不到下载文件的路径。我试图用名称(我在Google文档中看到的名称)搜索文件是徒劳的。
如何访问下载的文件?我怎样才能访问 "content"?请与我分享您的见解!
最佳
这只会将字符串添加到您需要在完成后将其写入文件的 StringIo 对象
stringObj = StringIO.new
file_id = 'xxxxxx' content = google_drive.export_file(file_id, 'application/pdf', download_dest: stringObj )
File.open('detination.txt', 'w') do |f|
f.puts(stringObj.read)
end
就我而言,上面的答案不起作用。我正在使用 google-api-client ~> 0.28.4
和 Rails 5.2.2
。
我只是想使用驱动器 API 下载 Google 电子表格。我有一项身份验证服务和一项使用 Service Account.
访问驱动器帐户的服务
这是将我的rails服务器中的文件下载到本地文件的服务方法:
def download_file(file_id)
content = service.export_file(
file_id,
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
download_dest: "tmp/#{file_id}.xlsx"
)
end
然后在控制器中读取该文件并在响应中将该文件传递给客户端,如下所示:
def download_file
file_id = params[:file_id] || ''
drive_service = GoogleApisService::Drive.new
file_name = drive_service.download_file(file_id)
send_file "tmp/#{file_id}.xlsx", type: "application/xlsx", filename: "#{file_id}.xlsx", disposition: 'inline'
end
这就是我将下载的文件从 Google 驱动器保存到 临时文件 的方式,然后将其提供给响应。
我正在尝试使用 Ruby 下载 google 文档文件。我找不到下载文件的路径。我在 ruby 中使用 'export_file' 方法命令如下:
file_id = 'xxxxxx' 内容 = google_drive.export_file(file_id, 'application/pdf', download_dest: StringIO.new)
控制台响应如下
正在写入块(1389 字节) 写入块(1389 字节) 写入块(1389 字节) 写入块(1389 字节) 写入块(896 字节) 写入块(2 个字节) 写入块(1234 字节) 成功 - #
=>#
似乎下载了一些东西,但是在 rails 中,我找不到下载文件的路径。我试图用名称(我在Google文档中看到的名称)搜索文件是徒劳的。
如何访问下载的文件?我怎样才能访问 "content"?请与我分享您的见解!
最佳
这只会将字符串添加到您需要在完成后将其写入文件的 StringIo 对象
stringObj = StringIO.new
file_id = 'xxxxxx' content = google_drive.export_file(file_id, 'application/pdf', download_dest: stringObj )
File.open('detination.txt', 'w') do |f|
f.puts(stringObj.read)
end
就我而言,上面的答案不起作用。我正在使用 google-api-client ~> 0.28.4
和 Rails 5.2.2
。
我只是想使用驱动器 API 下载 Google 电子表格。我有一项身份验证服务和一项使用 Service Account.
这是将我的rails服务器中的文件下载到本地文件的服务方法:
def download_file(file_id)
content = service.export_file(
file_id,
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
download_dest: "tmp/#{file_id}.xlsx"
)
end
然后在控制器中读取该文件并在响应中将该文件传递给客户端,如下所示:
def download_file
file_id = params[:file_id] || ''
drive_service = GoogleApisService::Drive.new
file_name = drive_service.download_file(file_id)
send_file "tmp/#{file_id}.xlsx", type: "application/xlsx", filename: "#{file_id}.xlsx", disposition: 'inline'
end
这就是我将下载的文件从 Google 驱动器保存到 临时文件 的方式,然后将其提供给响应。