public List <string> uploadFiles(List <UploadInfo> toUpload, CommonDescriptor folderDestination) { List <string> newFileIDs = new List <string>(); var _googleDriveService = InitializeAPI.googleDriveService; GoogleDriveCommunicationParser gdcp = new GoogleDriveCommunicationParser(); FilesResource.CreateMediaUpload request; string mimeType, fileName; foreach (UploadInfo uInfo in toUpload) { //get the fileType using the gdcp conversion method. fileName = uInfo.getFileName(); mimeType = gdcp.getMimeType(fileName.Substring(fileName.IndexOf('.'))); Google.Apis.Drive.v3.Data.File fileMetaData = new Google.Apis.Drive.v3.Data.File(); fileMetaData.Name = fileName; fileMetaData.Parents = new List <string> { folderDestination.FileID }; request = _googleDriveService.Files.Create(fileMetaData, uInfo.getFileStream(), mimeType); request.Fields = "id"; request.Upload(); uInfo.getFileStream().Close(); newFileIDs.Add(request.ResponseBody.Id); } return(newFileIDs); }
public void getMimeTypeTest() { var gdcp = new GoogleDriveCommunicationParser(); string oldEx, newEx; oldEx = ".doc"; newEx = gdcp.getMimeType(oldEx); if (newEx != "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { Assert.Fail(); } }
public void convertExtensionTest() { var gdcp = new GoogleDriveCommunicationParser(); string oldEx, newEx; oldEx = "application/vnd.google-apps.document"; newEx = gdcp.convertExtension(oldEx); if (newEx != ".doc") { Assert.Fail(); } }
public void createCommonDescriptorTest() { GoogleDriveCommunicationParser gdcp = new GoogleDriveCommunicationParser(); //string json = "{ \"FileName\":\"Delt Calendar 2015\",\"FileType\":\"application/vnd.google-apps.spreadsheet\",\"FilePath\":\"GoogleDrive\\Delta Tau Delta - Beta Gamma\\The Delt Library\",\"FileID\":\"1Sjaiv_xT_wvuoSvjy7lQeU09QY6kQ6DLuSRciYvx9ys\",\"LastModified\":\"Date(1449039649000)\",\"FileSize\":0}"; //string relPath = "GoogleDrive//Delta Tau Delta - Beta Gamma//The Delt Library"; //var cd = gdcp.createCommonDescriptor(relPath, json); string cd = null; if (cd == null) { Assert.IsTrue(true); } //Assert.Fail(); }
public async Task <bool> downloadFileAsync(CommonDescriptor cd) { var _googleDriveService = InitializeAPI.googleDriveService; //TODO: THE MIMETYPE THIS IS CAN'T BE THE SAME MIMETYPE AS WHAT IT WAS SAVED. It needs to be an export type. //https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents string extension, mimeType = ""; //figure out the mimetype by using the extension in the file name. GoogleDriveCommunicationParser gdcp = new GoogleDriveCommunicationParser(); if (cd.FileName.IndexOf('.') != -1) { //has an extension. extension = cd.FileName.Substring(cd.FileName.IndexOf('.')); //gets the extension. } else { //get a 'default' extension based on the format, convert to a real extension extension = cd.FileType; extension = gdcp.convertExtension(extension); if (extension == null) { //still can't find a good extension //not able to be downloaded, cancel download //TODO: ban the user from pressing download on these kinds of files? return(false); } } mimeType = gdcp.getMimeType(extension); if (mimeType == null) { //user cancelled giving us a new extension, cancel the download return(false); } var request = _googleDriveService.Files.Get(cd.FileID); var stream = new MemoryStream(); WindowsDownloadManager wdm = new WindowsDownloadManager(); request.MediaDownloader.ProgressChanged += (IDownloadProgress progress) => { switch (progress.Status) { case DownloadStatus.Downloading: { Console.WriteLine(progress.BytesDownloaded); break; } case DownloadStatus.Completed: { Console.WriteLine("Download complete."); break; } case DownloadStatus.Failed: { Console.WriteLine("Download failed."); break; } } }; try { IDownloadProgress x = await request.DownloadAsync(stream); wdm.downloadFile(stream, cd.FileName); } catch (Exception e) { Console.WriteLine(e); return(false); } return(true); }
public GoogleDriveCalls() { googleCommParser = new GoogleDriveCommunicationParser(); }