简体   繁体   中英

Upload files to google drive folder using PHP or javascript

I'm making a website in which user can upload large files. and i want these files to be saved on my google drive folder and their path can be stored in my database, with which i can access these files. I have followed this google drive documentation: https://developers.google.com/drive/v3/web/quickstart/js

function listFiles() {
    gapi.client.drive.files.list({
      'pageSize': 10,
      'fields': "nextPageToken, files(id, name)"
    }).then(function(response) {
      appendPre('Files:');
      var files = response.result.files;
      if (files && files.length > 0) {
        for (var i = 0; i < files.length; i++) {
          var file = files[i];
          appendPre(file.name + ' (' + file.id + ')');
        }
      } else {
        appendPre('No files found.');
      }
    });
  }

After running this code from documentation, it shows me list of all the files in my drive. I don't want this. All i want is to add a choose file button, which will upload the file to my drive. I cant understand how to add this functionality. please if anybody can guide me.

It's showing you a list of files because if you observe closely the method is named listFiles and the method being called is Files.list .

Since you're ok with Javascript, use the Picker API Quickstart . The sample is easy to follow. If you're going to use the quickstart code, remove the .setDeveloperKey(developerKey) part as it will cause errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM