Is there a way to create visible files on google drive?

202

I found the solution by myself. When I am specifying the parent folders and metadata, I should have left the parent folder blank as it is stated in description of variable.

The IDs of the parent folders which contain the file. If not specified as part of a create request, the file will be placed directly in the user's My Drive folder. If not specified as part of a copy request, the file will inherit any discoverable parents of the source file. Update requests must use the addParents and removeParents parameters to modify the parents list.

I hope it helps anyone who visited this page.

Share:
202
Zahid Tekbaş
Author by

Zahid Tekbaş

Updated on December 19, 2022

Comments

  • Zahid Tekbaş
    Zahid Tekbaş over 1 year

    I'm using Drive Api to make users upload and store files on their Google Drive accounts. As I see for now, every file that user uploads is hidden under my app and can not be displayed on drive without my app. I want them to display the files they upload just like regular images, videos etc. on Google Drive.

    Is there a way to accomplish this feature?

    EDITED:

    I would like to add a solution for this problem to help programmers who visit this page.

    Let's create the folder we want to store our files inside:

        var client = GoogleHttpClient(await account.authHeaders);
        var drive = ga.DriveApi(client);
        ga.File fileMetadata = ga.File();
        fileMetadata.name = "ourFolderName";
        fileMetadata.mimeType = "application/vnd.google-apps.folder";
    
        var response = await drive.files.create(fileMetadata);
        print("response file id: ${response.id}");
        writeFolderID(response.id);
    

    writeFolderID method contains some codes that writes the ID to local db for further usage in app.

    When I try to upload something, I gotta add folderID to file.parents field in our File variable. Then create the file in drive.

    
        var client = GoogleHttpClient(await googleSignInAccount.authHeaders);
        var drive = ga.DriveApi(client);
        ga.File fileToUpload = ga.File();
        var file = await FilePicker.getFile();
    
    
        String folderID = await getFolderID("folderKey"); //getFolderID is a function that retrieves folderID we have created before.
    // In order to upload a file to a folder in drive api, we have to save the folderID at creation moment. 
    
    
        fileToUpload.parents = [folderID];
        fileToUpload.name = path.basename(file.absolute.path);
        var response = await drive.files.create(
        fileToUpload,
        uploadMedia: ga.Media(file.openRead(), file.lengthSync()),
        );
    
    

    Afterwards, you can display "ourFolderName" in Google Drive easily and can make interactions.