I'm having trouble creating a folder in Google Drive using the google-drive-api library in ruby. I can successfully log in, list folders, even add a file to the root folder. I have a folder called 'Applications' under root folder. Listing all files show the id for this folder, lets call it "0BwiVxEBt'. In my controller I init the google drive connection successfully (as I'm able to list all files) and then call the create_parent('Test') method which is in my google_drive_connection.rb:
def create_folder (title)
file = @drive.files.insert.request_schema.new({
'title' => title,
'description' => title,
'mimeType' => 'application/vnd.google-apps.folder'
})
file.parents = [{"id" => '0BwiVxEBt'}] # 0BwiVxEBt is id for Applications folder
media = Google::APIClient::UploadIO.new(title, 'application/vnd.google-apps.folder')
result = @client.execute(
:api_method => @drive.files.insert,
:body_object => file,
:media => media,
:parameters => {
'uploadType' => 'multipart',
#'convert' => false,
'alt' => 'json'})
if result.status == 200
return result.data
else
puts "An error occurred: #{result.data['error']['message']}"
return nil
end
end
For what I saw in other post to insert a folder is just like a file insert (which works fine in ahother method in this rb file), a title with no extension, and the mimeType as 'application/vnd.google-apps.folder'
Error: No such file or directory - Test
Probably is a minor issue, but can't seem to find it!
Thanks for any pointer / help provided.
EDIT Found the problem, so for anyone interested in the solution, for folders you just need to send the metadata in the request, no need for media part, just needs body (metadata) information, so my 'create_folder' method results in:
def create_folder (title)
file = @drive.files.insert.request_schema.new({
'title' => title,
'description' => title,
'mimeType' => 'application/vnd.google-apps.folder'
})
file.parents = [{"id" => '0BwiVxEBt'}] # 0BwiVxEBt is id for Applications folder
result = @client.execute(
:api_method => @drive.files.insert,
:body_object => file)
if result.status == 200
return result.data
else
puts "An error occurred: #{result.data['error']['message']}"
return nil
end
end