Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
create public folder and allow user to create files into the particular folder

I am creating an application using asp.net mvc and javascript in which I am creating folders and creating document inside those folders,

below is my code to create folders and docs

function createFolder() {
    loadClient('https://www.googleapis.com/discovery/v1/apis/drive/v3/rest', function () {
        var body = {
            'name': document.getElementById('txtFolderName').value,
            'mimeType': "application/vnd.google-apps.folder",
            'parents': ['1R7c6lCV_qRxSTVHnbefLN4vJY0ZTMFUW']
        };

        return gapi.client.drive.files.create({
            'resource': body
        }).then(function (response) {
            console.log("Response", response);
        }, function (err) { console.error("Execute error", err); });
    })
}

function execute() {
    loadClient('https://docs.googleapis.com/$discovery/rest?version=v1', function () {
        return gapi.client.docs.documents.create({
            "resource": {
                "title": document.getElementById('txtTitle').value
            }
        })
            .then(function (response) {
                // Handle the results here (response.result has the parsed body).
                console.log("Response", response);
            },
                function (err) { console.error("Execute error", err); });
    })
}

now I want to create folders which will be accessible to everyone of my organization and insert the file in those folder

for example I have folder Named as "My company" and when I create a file, the file should be created inside "My company" folder

thanks for your time

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe your goal is as follows.

  • You want to create a new folder and want to publicly share the created folder as the writer.
  • You want to achieve this using googleapis for Javascript.

In this case, how about the following modification?

Modified script:

From:

return gapi.client.drive.files.create({
    'resource': body
}).then(function (response) {
    console.log("Response", response);
}, function (err) { console.error("Execute error", err); });

To:

gapi.client.drive.files.create({ 'resource': body })
.then(function (response) {
  console.log("Response", response);

  // Created folder is publicly shared.
  var folderId = response.result.id;
  gapi.client.drive.permissions.create({
    "fileId": folderId,
    "resource": {"role": "writer", "type": "anyone" }
  })
  .then(function (res) {
    console.log(res);
  }, function (err) {
    console.log(err.result.error.message);
  });

  // Create new Google Document to the created folder.
  var body = {
    'name': "sample filename",
    'mimeType': "application/vnd.google-apps.document",
    'parents': [folderId]
  };
  gapi.client.drive.files.create({ 'resource': body })
  .then(function (res) {
    console.log(res);
  }, function (err) {
    console.log(err.result.error.message);
  });

}, function (err) {
  console.error("Execute error", err);
});
  • I added the script for one more thing I want to achieve is that I want to create document in those a particular folder of my google drive.

Reference:

  • Permissions: create
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!