private void BuildResultString(UnityGoogleDrive.Data.File file) { result = string.Format("Name: {0} Size: {1:0.00}MB Created: {2:dd.MM.yyyy HH:MM:ss}", file.Name, file.Size * .000001f, file.CreatedTime); }
public async UniTask <bool> UploadDataAsync() { var success = true; for (int i = 0; i < uploadFiles.Count; i++) { UploadProgress = i / (float)uploadFiles.Count; OnUploadProgress?.Invoke(UploadProgress); var uploadFile = uploadFiles[i]; var googleFile = new UnityGoogleDrive.Data.File { Content = uploadFile.ByteContent }; var fileId = await Helpers.CreateOrUpdateFileAtPathAsync(googleFile, uploadFile.Path, uploadMimeType : "text/plain"); if (string.IsNullOrEmpty(fileId)) { success = false; break; } } OnUploadProgress?.Invoke(1f); UploadProgress = 0f; return(success); }
/// <summary> /// Downloads a file's content by ID and creates an <see cref="AudioClip"/> based on the retrieved data. /// Using this method significantly reduces memory reallocation compared to downloading raw bytes and creating an audio clip manually in script. /// Be aware, that Unity support for encoding formats is limited depending on the platform. /// Eg: mp3 not supported on editor and standalones, ogg not availabile on WebGL, etc. /// </summary> /// <param name="file">Meta of the audio file to download. Must have a valid <see cref="Data.File.Id"/> and <see cref="Data.File.MimeType"/> fields.</param> public static DownloadAudioRequest DownloadAudio(Data.File file) { var fileId = file.Id; if (string.IsNullOrEmpty(fileId)) { Debug.LogError("Invalid file ID."); } var audioType = AudioType.UNKNOWN; switch (file.MimeType) { case "audio/aiff": audioType = AudioType.AIFF; break; case "audio/mpeg": audioType = AudioType.MPEG; break; case "audio/ogg": audioType = AudioType.OGGVORBIS; break; case "video/ogg": audioType = AudioType.OGGVORBIS; break; case "audio/wav": audioType = AudioType.WAV; break; } if (audioType == AudioType.UNKNOWN) { Debug.LogError("Unsupported audio MIME type."); } return(new DownloadAudioRequest(fileId, audioType)); }
private void putInFolderInThread(UnityGoogleDrive.Data.File file) { GoogleDriveFiles.CreateRequest request; PhotoSession.PhotoFolder folder = instance.getFolder(instance.folderNameGlobal, instance.folderDateGlobal); string p = Path.Combine(datapath, folder.folderName + "_" + folder.data + "_" + folder.modelid + "_" + folder.userid); foreach (var link in folder.files) { string path = Path.Combine(p, link.name); Sprite sprite = SpriteLoader.GetSpriteFromFileWithCompression(path); var filen = new UnityGoogleDrive.Data.File() { Name = GenerateName() + GetId(link.id + 1), Content = sprite.texture.EncodeToPNG(), Parents = new List <string> { file.Id } }; request = GoogleDriveFiles.Create(filen); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send().OnDone += instance.PrintResult; } instance.folderNameGlobal = ""; }
private async void FindFilesByPathAsync(string path) { running = true; if (File.Exists(uploadFilePath)) { var uploadFile = new UnityGoogleDrive.Data.File { Content = File.ReadAllBytes(uploadFilePath) }; uploadFile.Id = await Helpers.CreateOrUpdateFileAtPathAsync(uploadFile, filePath); BuildResults(new List <UnityGoogleDrive.Data.File> { uploadFile }); } else { var files = await Helpers.FindFilesByPathAsync(path, fields : new List <string> { "files(id, name, size, mimeType, modifiedTime)" }, mime : folder?Helpers.FolderMimeType : null); BuildResults(files); } running = false; }
private void SuccesLogin(WWW www) { ServerController.onSuccessHandler -= SuccesLogin; ServerController.onSuccessHandler = null; Models.user = JsonUtility.FromJson <Garage>(www.text); Debug.Log(www.text); Debug.Log(Models.user.user); LoginPage.SetActive(false); GlobalParameters.isLogined = true; if (isSaveble) { SaveModelController.SaweUserData(); } if (!PlayerPrefs.HasKey("google")) { PlayerPrefs.SetInt("google", 0); var auth = new UnityGoogleDrive.Data.File() { Name = "authointification" }; GoogleDriveFiles.Create(auth).Send(); } CallMessage cmsg = new CallMessage(); cmsg.from = Models.user.user; cmsg.to = SystemInfo.deviceUniqueIdentifier; cmsg.comand = "login"; WEbSocketController.GetInstance.SendMessage(JsonUtility.ToJson(cmsg)); }
private void Upload(bool toAppData) { var content = File.ReadAllBytes(UploadFilePath); if (content == null) { return; } var file = new UnityGoogleDrive.Data.File() { Name = Path.GetFileName(UploadFilePath), Content = content }; if (toAppData) { file.Parents = new List <string> { "appDataFolder" } } ; request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send().OnDone += PrintResult; }
private void PrintResult(UnityGoogleDrive.Data.File file) { result = string.Format("Name: {0} Size: {1:0.00}MB Created: {2:dd.MM.yyyy HH:MM:ss}\nID: {3}", file.Name, file.Size * .000001f, file.CreatedTime, file.Id); }
public DownloadRequest(string fileId) : base(fileId) { Alt = "media"; ResponseData = new Data.File() { Id = fileId }; }
public DownloadRequest(string fileId, RangeInt?downloadRange = null) : base(fileId) { Alt = "media"; ResponseData = new Data.File() { Id = fileId }; DownloadRange = downloadRange; }
private void RenderImage(UnityGoogleDrive.Data.File file) { var texture = new Texture2D(file.ImageMediaMetadata.Width.Value, file.ImageMediaMetadata.Height.Value, TextureFormat.RGBA32, false); texture.LoadImage(file.Content); var rect = new Rect(0, 0, texture.width, texture.height); SpriteRenderer.sprite = Sprite.Create(texture, rect, Vector2.one * .5f); }
public static void Export() { var file = new UnityGoogleDrive.Data.File() { Name = string.Format("{0}_log.txt", DateTime.Now.ToLongTimeString()), Content = Encoding.Default.GetBytes(_log.ToString()) }; GoogleDriveFiles.Create(file).Send(); }
private void CopyFile() { var file = new UnityGoogleDrive.Data.File() { Id = fileId, Name = string.IsNullOrEmpty(copyName) ? null : copyName }; request = GoogleDriveFiles.Copy(file); request.Fields = new List <string> { "name, size, createdTime" }; request.Send().OnDone += BuildResultString; }
IEnumerator Upload() { var data = new UnityGoogleDrive.Data.File { Name = "Test.txt", Content = System.Text.Encoding.UTF8.GetBytes("Hello Google Drive ") }; var req = UnityGoogleDrive.GoogleDriveFiles.Create(data); print("Start Test Upload"); yield return(req.Send()); print("Finish Test Upload"); }
public IEnumerator Test009_FilesUpdate() { const string UPDATED_NAME = "UpdatedName"; var file = new UnityGoogleDrive.Data.File() { Name = UPDATED_NAME }; var request = GoogleDriveFiles.Update(copiedFileId, file); yield return(request.Send()); Assert.IsFalse(request.IsError); Assert.AreEqual(request.ResponseData.Name, UPDATED_NAME); }
private void Upload() { var content = ImageToUpload.EncodeToPNG(); var file = new UnityGoogleDrive.Data.File() { Name = "TestUnityGoogleDriveFilesUpload.png", Content = content, MimeType = "image/png" }; request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send().OnDone += PrintResult; }
public void SendDataFile() { string filePath = Application.persistentDataPath + "/datacollection.txt"; string testContent = File.ReadAllText(filePath); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(testContent); var file = new UnityGoogleDrive.Data.File() { Name = "BiodegradabilityCollectedData.txt", Content = bytes }; GoogleDriveFiles.Create(file).Send().OnDone += file1 => _response = Encoding.UTF8.GetString(file.Content); }
public void UploadSnap() { imageToUpload = snapShot.virtualPhoto; var content = imageToUpload.EncodeToPNG(); var file = new UnityGoogleDrive.Data.File() { Name = filename, Content = content, MimeType = "image/png" }; request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send(); }
void Submit() { AudioClip myClip = SavWav.TrimSilence(audioSource.clip, 0.1f); string fileName = "virtualshackrecording_" + myNum; string outputLocation = SavWav.Save(fileName, myClip); Byte[] content = System.IO.File.ReadAllBytes(outputLocation); File file = new File { Name = Path.GetFileName(outputLocation), Content = content }; GoogleDriveFiles.Create(file).Send().OnDone += result => { Debug.Log("Uploaded: " + result.Name); }; myNum++; }
private void Upload() { var content = File.ReadAllBytes(UploadFilePath); if (content == null) { return; } var file = new UnityGoogleDrive.Data.File() { Name = Path.GetFileName(UploadFilePath), Content = content }; request = GoogleDriveFiles.CreateResumable(file, resumableSessionUri); request.Send().OnDone += SaveSessionUri; }
public IEnumerator Test006_FilesCopy() { var file = new UnityGoogleDrive.Data.File() { Id = createdFileId }; var request = GoogleDriveFiles.Copy(file); request.Fields = new List <string> { "id" }; yield return(request.Send()); Assert.IsFalse(request.IsError); Assert.NotNull(request.ResponseData.Id); copiedFileId = request.ResponseData.Id; }
public IEnumerator Test003_FilesCreate() { var content = Resources.Load <Texture2D>(TEST_RESOURCE_PATH).EncodeToPNG(); var file = new UnityGoogleDrive.Data.File() { Name = "AutoTestUpload", Content = content }; var request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id" }; yield return(request.Send()); Assert.IsFalse(request.IsError); Assert.NotNull(request.ResponseData.Id); createdFileId = request.ResponseData.Id; }
// Write data using TestItemView private async void InitializePanView(GameObject viewPrefab, UnityGoogleDrive.Data.File file, bool isDownloaded) { TestItemView view = new TestItemView(viewPrefab.transform); view.titleText.text = file.Name.Remove(file.Name.IndexOf('.')); view.imageThumbnail.sprite = await DownloadThumbnail(file.ThumbnailLink); if (isDownloaded) { view.downloadButton.gameObject.SetActive(false); } view.downloadButton.GetComponent <Button>().onClick.AddListener( () => { tempName = file.Name.Remove(file.Name.IndexOf('.')); DownloadTexture(file.Id); } ); }
void Upload() { Texture2D texCopy = new Texture2D(image.width, image.height, image.format, image.mipmapCount > 1); texCopy.LoadRawTextureData(image.GetRawTextureData()); texCopy.Apply(); var content = texCopy.EncodeToPNG(); var file = new UnityGoogleDrive.Data.File() { Name = "proof.png", Content = content, MimeType = "image/png" }; request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send().OnDone += PrintResult; }
// Start is called before the first frame update void Start() { //GoogleDriveFiles.Create(file).Send(); //var file = new UnityGoogleDrive.Data.File { Name = "user-0", MimeType = "application/vnd.google-apps.folder"}; //var parentID = UnityGoogleDrive.Helpers.CreateOrUpdateFileAtPathAsync(file, "/Test/user-0"); var bytes = System.IO.File.ReadAllBytes("Builds/Data/User-5/20190716_IMU_Data.csv"); var file = new UnityGoogleDrive.Data.File { Name = "20190716_IMU_Data.csv", Content = bytes }; UnityGoogleDrive.Helpers.CreateOrUpdateFileAtPathAsync(file, "/Test/user-0/20190716_IMU_Data.csv"); //bytes = System.IO.File.ReadAllBytes("Builds/Data/User-5/20190716_Kinect_Data.csv"); //file = new UnityGoogleDrive.Data.File { Name = "20190716_Kinect_Data.csv", Content = bytes }; //UnityGoogleDrive.Helpers.CreateOrUpdateFileAtPathAsync(file, "/Test/user-0/20190716_Kinect_Data.csv"); //UnityGoogleDrive.Helpers.CreateOrUpdateFileAtPathAsync(file, "/Test/20190716_IMU_Data.csv"); }
//do the upload to google drive public void upload() { if (data.Length == 0) { return; } var file = new UnityGoogleDrive.Data.File() { Name = "log_" + uploadID.ToString() + ".txt", Parents = new List <string> { "1UANcfS3aWNjJwmsb1dA--FUDX_Guj2rF" }, //<<<<<------hacked in for now Content = Encoding.ASCII.GetBytes(data) }; var result = GoogleDriveFiles.Create(file).Send(); //TODO: add some flag to the OnDone event to manage conflicts (or call infrequently). uploadID += 1; clearData(); }
private void SetResult(UnityGoogleDrive.Data.File file) { result = Encoding.UTF8.GetString(file.Content); var path = Application.persistentDataPath + "/" + fileName.Replace(" ", ""); File.WriteAllBytes(path, file.Content); //Assign the file to the placement object //successful retreival of file using (var assetLoader = new AssetLoader()) { var ops = AssetLoaderOptions.CreateInstance(); //Creates the AssetLoaderOptions instance. //AssetLoaderOptions let you specify options to load your model. //(Optional) You can skip this object creation and it's parameter or pass null. //You can modify assetLoaderOptions before passing it to LoadFromFile method. You can check the AssetLoaderOptions API reference at: //https://ricardoreis.net/trilib/manual/html/class_tri_lib_1_1_asset_loader_options.html ops.UseOriginalPositionRotationAndScale = true; ops.Scale = 1 / 1000f; var wrapperGameObject = gameObject; //Sets the game object where your model will be loaded into. //(Optional) You can skip this object creation and it's parameter or pass null. var myGameObject = assetLoader.LoadFromFile(path, ops, wrapperGameObject); //Loads the model synchronously and stores the reference in myGameObject. var ObjectToPlace = Instantiate(myGameObject); if (ObjectToPlace != null) { //After instantiating object kill UI GameObject.Find("Canvas").SetActive(false); //Assign variable to TapToPlace GameObject.Find("AR Session Origin").GetComponent <TapToPlace>().objectToPlace = ObjectToPlace; } } //EditorUtility.RevealInFinder(path); }
static void UploadApk(string pathToBuildProject) { //Debug.Log($"Build Target is Android Start Uploading projectPath:{pathToBuildProject}"); var apkName = pathToBuildProject.Split(new[] { '/' }).Last();// apkのファイル名を取得 // Debug.Log($"Name:{apkName}"); if (File.Exists(pathToBuildProject)) { var apk = new UnityGoogleDrive.Data.File { Name = apkName, Content = File.ReadAllBytes(pathToBuildProject) }; var req = UnityGoogleDrive.GoogleDriveFiles.Create(apk); req.OnDone += response => { if (req.IsError) { Debug.LogError(req.Error); } if (req.IsDone) { Debug.Log("Upload Success! See your Google Drive"); Debug.Log(response.WebViewLink); if (!string.IsNullOrEmpty(response.WebViewLink)) { Application.OpenURL(req.ResponseData.WebViewLink); } } }; req.Send();//upload } else { Debug.Log($"Built File Path:{pathToBuildProject} File Not Exists"); } }
private IEnumerator SaveToGoogleDrive(GameObject loadObject, bool hasGoogleDriveSaveFile) { var file = new UnityGoogleDrive.Data.File() { Name = "PS_SaveData", Content = File.ReadAllBytes(Application.persistentDataPath + "/SaveData.xml") }; if (!hasGoogleDriveSaveFile) { var request = GoogleDriveFiles.Create(file); yield return(request.Send()); saveData.googleDriveSaveFileId = request.ResponseData.Id; } else { var request = GoogleDriveFiles.Update(saveData.googleDriveSaveFileId, file); yield return(request.Send()); } loadObject.SetActive(false); StructureManager.instance.NewNotification("Save Completed"); }
void GetResults(UnityGoogleDrive.Data.FileList fileList) { byte[] content = File.ReadAllBytes(getPath()); UnityGoogleDrive.Data.File file = new UnityGoogleDrive.Data.File() { Name = Path.GetFileName(getPath()), Content = content }; if (fileList.Files.Count >= 1) { for (int i = 0; i < fileList.Files.Count; i++) { if (fileList.Files[i].Name == fileName) { GoogleDriveFiles.Update(fileList.Files[i].Id, file).Send(); } } } else { GoogleDriveFiles.Create(file).Send(); } // Debug.Log("done"); }