Home > Software design >  Google drive picker selected files are not publicly accessible
Google drive picker selected files are not publicly accessible

Time:12-14

I am trying to open the selected file from google drive picker in incognito mode, but it is asking to sign in accounts. I want that file as a public file. Without logging in our account, we should access it.

My picker function in typescript,

createPicker(): void {
    var uploadView = new window["google"].picker.DocsUploadView();
    const view = new window["google"].picker.View(
      window["google"].picker.ViewId.DOCS
    );
    const picker = new window["google"].picker.PickerBuilder()
      .enableFeature(window["google"].picker.Feature.SIMPLE_UPLOAD_ENABLED)
      .enableFeature(window["google"].picker.Feature.MULTISELECT_ENABLED)
      .setDeveloperKey( this.googleDriveApiKey)
      .setAppId(this.googleDriveProjectId)
      .addView(view)
      .addView(uploadView)
      .setOAuthToken(this.accessToken)
      .setCallback(this.pickerCallback.bind(this))
      .build();
    picker.setVisible(true);
  }

Drive picker enter image description here

enter image description here

CodePudding user response:

As mentioned by naveen, you need to be authenticated as an end user to access files via Picker. It's not an optional step.

Reference:

CodePudding user response:

In the picker callback function, after we picked the files, we can set permissions to it.

 if(data && data['docs']) {
          data['docs'].forEach((file)=>{
            var body = {
              'type': 'anyone',
              'role': 'reader'
            }
            var request = window['gapi'].client.drive.permissions.create({
              'fileId': file.id,
              'resource': body
              });
              request.execute(function(resp) {});
          });

This code make all the selected files to be accessible without signing in.

  • Related