0
我正在使用Google Ruby API客戶端下載Google Drive文件(使用downloadUrl)。我能夠成功下載文件,但接下來我要提示Web用戶將文件保存在本地(到他選擇的位置)。在執行下面的代碼之後我該怎麼做?如何提示用戶在Rails中保存從Google Drive API下載的文件
client = Google::APIClient.new
drive = client.discovered_api('drive', 'v2')
client.authorization.client_id = ENV["GOOGLE_CLIENT_ID"]
client.authorization.client_secret = ENV["GOOGLE_CLIENT_SECRET"]
client.authorization.redirect_uri = '...'
client.authorization.access_token = '...'
client.authorization.scope = https://www.googleapis.com/auth/drive
result = client.execute(
:api_method => drive.files.get,
:version => 'v2',
:parameters => { 'fileId' => "..."}
)
download_url = result.data.downloadUrl
if download_url
fileResult = client.execute(:uri => download_url)
else
#HANDLE ERRORS
....
end
# WHAT TO ADD HERE TO PROMPT USER TO SAVE THE FILE LOCALLY?
您可以用'send_file'這樣'由send_file([File對象]類型:[您的MIME類型],佈局:假的,配置: '附件') '這會將你的文件作爲附件輸出到瀏覽器,這將提示用戶打開或保存。 – engineersmnky