Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's actually pretty straightforward. A folder in Google Drive is a <code>GoogleDrive::Collection</code> (<a href="http://gimite.net/doc/google-drive-ruby/GoogleDrive/Collection.html" rel="noreferrer">http://gimite.net/doc/google-drive-ruby/GoogleDrive/Collection.html</a>) in <a href="https://github.com/gimite/google-drive-ruby/" rel="noreferrer">google-drive-ruby gem</a>. Therefore, what you may do with google-drive-ruby is first create a file, and then add it to a collection via the <code>GoogleDrive::Collection#add(file)</code> method. </p> <p>This also mimics the way that Google Drive actually works: upload a file to the root collection/folder, <em>then</em> add it to other collections/folders.</p> <p>Here's some sample code, which I had written. It should work - with perhaps some minor tweaking for your specific use case - based on the context that you had provided:</p> <pre><code># this example assumes the presence of an authenticated # `GoogleDrive::Session` referenced as `session` # and a file named `test.zip` in the same directory # where this example is being executed # upload the file and get a reference to the returned # GoogleSpreadsheet::File instance file = session.upload_from_file("test.zip", "test") # get a reference to the collection/folder to which # you want to add the file, via its folder name folder = session.collection_by_title("my-folder-name") # add the file to the collection/folder. # note, that you may add a file to multiple folders folder.add(file) </code></pre> <p>Further, if you only want to create a new folder, without putting any files in it, then just add it to the root collection:</p> <pre><code>session.root_collection.create_subcollection("my-folder-name") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload