Skip to content

Instantly share code, notes, and snippets.

@mspvirajpatel
Created September 18, 2017 05:23
Show Gist options
  • Save mspvirajpatel/2a76798be175fedbc53b823ac43da788 to your computer and use it in GitHub Desktop.
Save mspvirajpatel/2a76798be175fedbc53b823ac43da788 to your computer and use it in GitHub Desktop.
func uploadGoogleURL(imageName: String,contents : String,parentsFolderId : String?) {
self.showProgressHUD(viewController: self, title: "uploadImage".localize(), subtitle: "")
let metadata = GTLRDrive_File.init()
metadata.name = imageName
if parentsFolderId != nil
{
let folderId: String = parentsFolderId!
metadata.parents = [folderId]
}
let uploadParameters = GTLRUploadParameters.init(fileURL: URL.init(string: contents)!, mimeType: "application/bin")
uploadParameters.useBackgroundSession = true
// uploadParameters.shouldSendUploadOnly = true
// uploadParameters.shouldUploadWithSingleRequest = true
let query = GTLRDriveQuery_FilesCreate.query(withObject: metadata, uploadParameters: uploadParameters)
query.fields = "id"
AppUtility.getAppDelegate().service.executeQuery(query) { (ticket, file, error) in
self.hideProgressHUD()
if error == nil {
let files : GTLRDrive_File = file as! GTLRDrive_File
print("File ID \(String(describing: files.identifier))")
if self.parentMedia != nil{
self.syncCloudData(isReload: true)
}
else
{
self.syncSingleCloudRoot(cloudType: .googleDrive)
}
}
else {
print("An error occurred: \(error!.localizedDescription)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment