Raviprakash Raviprakash - 1 month ago 7
Objective-C Question

Insert file into appdata folder

I am developing Mac application and want to store file in Google drive.The files should be hidden from the user.So my choice is to save in "appdata" folder. Using Drive sample code to upload file. To insert file into "appdata" folder am using this sample code. But when I insert the file is visible to user.It is not hidden.


  1. So Please let me know what are the changes necessary Drive sample
    code
    to upload file into "appdata" private folder. ?

  2. Do I need
    to create "appdata" folder for the first time?


Answer

After doing following changes to Drive Sample successfully uploaded file to app data folder:

  1. Modified API scope to choose "https://www.googleapis.com/auth/drive.appdata" :

GTMOAuth2WindowController *windowController = [GTMOAuth2WindowController controllerWithScope:@"https://www.googleapis.com/auth/drive.appdata" clientID:clientID clientSecret:clientSecret keychainItemName:kKeychainItemName resourceBundle:frameworkBundle];

2.Obtain parent file reference. Here 'appdata' folder is the parent:

GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:@"appdata"];
        [service executeQuery:query
            completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *parentfile,
                                NSError *error) {
                /*Save parentfile for future reference*/}];

3.While uploading set file parent to app data folder. Using parent file reference obotained in the previous step

GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
        parentRef.identifier = parentfile.identifier;
        fileToUpload.labels.hidden = @YES;
        fileToUpload.parents = [NSArray arrayWithObjects: parentRef, nil];
Comments