How to get file size with REST API

984 views
Skip to first unread message

Guan Bin

unread,
Jul 11, 2016, 7:09:19 AM7/11/16
to Google APIs Client Library for Objective-C
I have uploaded a file with REST API, and I checked on my Google Drive account, that file does exist and its file size is about 42kB.

Then I want to get the file size with the following code: 

GTLRDriveQuery_FilesList * query = [GTLRDriveQuery_FilesList query];


    query.q = [NSString stringWithFormat:@"name='%@' and '%@' in parents and trashed=false", @"Meeting.caf", strFolderID];


   


    self.uploadTicket = [self.driveService executeQuery:query completionHandler:^(GTLRServiceTicket *ticket,


                                                                                  GTLRDrive_FileList * fList,


                                                                                  NSError *error)


                         {


                             if (error == nil)


                             {


                                 NSLog(@"Have results");


                                 for (int i = 0; i < [fList.files count]; i++)


                                 {

                                    GTLRDrive_File * test = [fList.files objectAtIndex:i];

                                                                               NSLog(@"file size: %llu", [test.size longLongValue]);

                                     NSLog(@"file name: %@", test.name);

                                }

                            }

                            else

                            {

                                NSLog(@"upload check query failed: %@", error.localizedDescription);

                            }


                             


                         }];


And the file size I got is 0.

in Old API, I can get file size by GTLDriveFile.fileSize,   And it seems that GTLRDrive_File.size does not do the job.

Is this a bug or did I do anything wrong?

Thomas Van Lenten

unread,
Jul 11, 2016, 10:46:54 AM7/11/16
to Google APIs Client Library for Objective-C
When did you last update your code before moving to the REST versions?  When the Drive team released their Version 3 api, they changed a bunch of things and we had to update the sample a fair amount to make things work; but when moving it to the REST version, we didn't hit anything that really worked differently from how Version 3 works on JSON-RPC.

I'm also guessing if you print out the test.size you'll find it is NULL, so it isn't that the server is sending you zero, it is that it isn't including the size.  If you take a look at the example, we hit this behavior and tried to document a hint at it:


So for the Drive api, you likely need to use a "field" parameter to list exactly what things you want the server to return. Why not exactly standard, I think the server team did this to avoid spending the time and bytes to send data clients don't want, and instead opted for requiring clients to state what fields they wanted.

TVL
Reply all
Reply to author
Forward
0 new messages