Created
September 18, 2017 05:23
-
-
Save mspvirajpatel/2a76798be175fedbc53b823ac43da788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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