title: How to return file object from google drive download
body: <p>I'm new to Rails.</p>
  
  <p>I have a method that downloads a file from google drive and saves it in the local disc. When the file is downloaded, the console returns <code>nil</code>, but the file is in the folder.</p>
  
  <p>I need to use this file in my controller, but if the download method is returning <code>nil</code> I can't pass it around as an object.</p>
  
  <p>download method:</p>
  
  <pre><code>def download
    found = google_files.select { |f| f.id == file_id }
    file_title = found.first.title
    file = session.file_by_title(file_title)
    path = File.join(Backup.base_directory, file_title)
    file.download_to_file("#{path}")
  end
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>def create
    # file_id = params.fetch(:file_id)
    file_id = "0Byyflt8z3jarbm5DZGNNVXZSWjg"
    @backup = DiscourseDownloadFromDrive::DriveDownloader.new(file_id).download
  end
  </code></pre>
  
  <p>console output after executing the download method:</p>
  
  <pre><code>[...]
  Writing chunk (1397 bytes)
  Writing chunk (1397 bytes)
  Writing chunk (1397 bytes)
  Writing chunk (619 bytes)
  Success - nil
  
  =&gt; nil
  [4] pry(main)&gt;
  </code></pre>
  
  <p>Logger:</p>
  
  <pre><code>Rails.logger.debug("&gt;&gt;&gt; @BACKUP &gt;&gt;&gt;: #{@backup.inspect}")
  
  D, [2017-09-07T20:21:24.835450 #7755] DEBUG -- : &gt;&gt;&gt; @BACKUP &gt;&gt;&gt;: nil
  </code></pre>
  
  <p>Any hint on how to proceed with this would be very much appreciated!</p>