-1

I'm trying to export my file to Google Share Drive. I was able to export to my own drive but I have not found any solution for the shared one yet.

Currently, what I have so far for uploading file to my drive are these two functions, one will be a public function that will simplify the interface, and another one will actually upload the file:

    public func uploadFile(
        _ folderName: String,
        filePath: String,
        MIMEType: String,
        onCompleted: ((String?, Error?) -> ())?) {
            
        search(folderName) { (folderID, error) in
                
            if let ID = folderID {
                self.upload(ID, path: filePath, MIMEType: MIMEType, onCompleted: onCompleted)
                
                // if not found, create a new one
            } else {
                self.createFolder(folderName, onCompleted: { (folderID, error) in
                    guard let ID = folderID else {
                        onCompleted?(nil, error)
                        return
                    }
                    self.upload(ID, path: filePath, MIMEType: MIMEType, onCompleted: onCompleted)
                })
            }
        }
    }
        // upload
    private func upload(
        _ parentID: String,
        path: String,
        MIMEType: String,
        onCompleted: ((String?, Error?) -> ())?) {
            
        ...
    }

Now I want to upload my files to a shared Drive and I found there are DriveID and Parent properties from this post but it is Node.js and not so sure how to work with it with iOS.

var fileMetadata = {
    name: fileName,
    mimeType: mime,
    'parents': [
        "0AFiiwdVdxetuUk9PVA"
    ],
    'teamDriveId': "0AFiiwdVdxetuUk9PVA"
}

Thank you!

Duc Dang
  • 186
  • 1
  • 14
  • Please include a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and what errors are you encountering. – CMB Aug 24 '21 at 20:47
  • Thank you for your recommendation, I have updated my question, there is no error, I just dont know how to save my files to a Shared Google Drive – Duc Dang Aug 25 '21 at 15:51

1 Answers1

1

You must add the supportsAllDrives=true query parameter to your upload request url.

Documentation: https://developers.google.com/drive/api/v3/enable-shareddrives

Mario Varchmin
  • 3,704
  • 4
  • 18
  • 33