Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drive.files.insert doesn't support parents #96

Closed
robbiet480 opened this issue Oct 21, 2013 · 18 comments
Closed

drive.files.insert doesn't support parents #96

robbiet480 opened this issue Oct 21, 2013 · 18 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@robbiet480
Copy link

No matter what I do, I can't get parents to be set on a file. Here's my current code:

googleapis.discover('drive', 'v2').execute(function(err, client) {
        var folder = client.drive.files
              .insert({title:'Test folder',mimeType:'application/vnd.google-apps.folder'})
              .withAuthClient(auth)
              .execute(function(err,result){
                if(err) console.error(err);
                var parents = [result.id] 

                var insert = client.drive.files
                      .insert({ title: 'My Document.txt', mimeType: 'text/plain', convert: 'true', parents: parents })
                      .withMedia('text/plain', 'Hello World!')
                      .withAuthClient(auth);
                insert.apiMeta.basePath = '/upload/drive/v2/';
                console.log(insert);
                insert.execute(function(err,result){
                  if(err) console.error(err);
                  console.log(result);
                });
              });

I can make the insert request find, and a list request. I've tried setting up the parents array with both raw elements and objects containing id and kind. Also, the basePath override is due to the fact that I keep getting errors stating that the URL needs to be /upload/drive/v2/files, not /drive/v2/files

Thanks for the help

@rakyll
Copy link
Contributor

rakyll commented Oct 30, 2013

parents should be [{ id: result.id }] instead of a list of IDs.

@rakyll rakyll closed this as completed Oct 30, 2013
@robbiet480
Copy link
Author

@rakyll I also tried that, as mentioned in my comment below the code.

@rakyll rakyll reopened this Dec 3, 2013
@omriiluz
Copy link

omriiluz commented Dec 3, 2013

robbiet480 - Can you try the upload function in my app and see if it works for you ?
it have been tested in many environments and scenarios and seems to work fine.
https://github.com/omriiluz/gdrive-sync

@rakyll
Copy link
Contributor

rakyll commented Dec 3, 2013

The code above sets parents as a list of IDs: [result.id]
Parents should be set as an list of objects with IDs: [{ id: result.id }]

@rakyll rakyll closed this as completed Dec 10, 2013
@despotix
Copy link

When I set the "convert" parameter to "true", "parents" is ignored. But if "convert" is "false" "parents" works fine.

Here is my upload function:

    var upload = function(client, cb) {
        client.drive.files.insert({
            title: 'My Document1',
            mimeType: 'text/csv',
            convert: true,
            parents: [
                {
                    'id': '0B31SIwvSUVG2UFBRTXdGU0J1U2s'
                }
            ]
        })
        .withMedia('text/csv', '1,2,3')
        .withAuthClient(auth).execute(cb);
    };

@rakyll
Copy link
Contributor

rakyll commented May 28, 2014

When I set the "convert" parameter to "true", "parents" is ignored.

convert is a query parameter, does the behaviour change when it's set as a query param? It looks like there is an API bug when it's a part of the body -- it should have been ignored.

var upload = function(client, cb) {
        client.drive.files.insert({
            convert: true
        },
        {
            title: 'My Document1',
            mimeType: 'text/csv',
            parents: [
                {
                    'id': '0B31SIwvSUVG2UFBRTXdGU0J1U2s'
                }
            ]
        })
        .withMedia('text/csv', '1,2,3')
        .withAuthClient(auth).execute(cb);
    };

@despotix
Copy link

Yes, your code works fine for me. Thank you.

@ryanseys
Copy link
Contributor

The separation between query parameters and body is so fine that many people trip up on this idea. This needs to be better documented. Leave this issue open for tracking purposes.

@pawelrychlik
Copy link

Seems like the library is changing pretty often recently. This works for me ("googleapis": "~1.0.3"):

drive.files.insert({
    resource: {
        title: "Hello.csv",
        mimeType: 'text/csv',
        parents: [ { id: "0B2CHMdG36QFcZlJJbBVmU3ppS0X" } ]
    },
    media: {
       mimeType: 'text/csv',
       body: "1,2,3"
    },
 }, function(err, resp) {});

@yangsibai
Copy link

@pawelrychlik Thank you!
And Google's documents suck!

@matomesc
Copy link

@pawelrychlik 👍

@ryanseys
Copy link
Contributor

@yangsibai

And Google's documents suck!

Which documents? Is there any way we can make them better? :)

@yangsibai
Copy link

@ryanseys SDK shouldn't change main api buy not change major version number. And there is not any document tell developers about this.

@ryanseys
Copy link
Contributor

When we changed the main API, we changed from 0.8.x to 1.0.x. The documentation is lacking an update on developers.google.com but here the documentation in this README should be up to date. Thanks for your comments.

@yangsibai
Copy link

Hope you can be serious about main api change. I'm sorry to said 'suck'. I was just crazy about the upgrade made my project couldn't work.

@ryanseys
Copy link
Contributor

@yangsibai Sorry to hear of your troubles. Check out the migration guide for everything you need to know about migrating your project from 0.x.x to 1.0.x

@yangsibai
Copy link

It’s ok now, thank you for your work. I get this trouble in 0.x.x upgrade, I shouldn't complain about the beta version,I was too sensitive.
在 2014年9月15日,上午10:14,Ryan Seys notifications@github.com 写道:

@yangsibai Sorry to hear of your troubles. Check out the migration guide for everything you need to know about migrating your project from 0.x.x to 1.0.x


Reply to this email directly or view it on GitHub.

@ryanseys
Copy link
Contributor

You're welcome! Thank you for your feedback.

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

9 participants