public void Put(string remotename, System.IO.Stream stream) { try { // Figure out if we update or create the file if (m_filecache.Count == 0) { List(); } GoogleDriveFolderItem[] files; m_filecache.TryGetValue(remotename, out files); string fileid = null; if (files != null) { if (files.Length == 1) { fileid = files[0].id; } else { Delete(remotename); } } var isUpdate = !string.IsNullOrWhiteSpace(fileid); var url = isUpdate ? string.Format("{0}/files/{1}?uploadType=resumable", DRIVE_API_UPLOAD_URL, Library.Utility.Uri.UrlPathEncode(fileid)) : string.Format("{0}/files?uploadType=resumable", DRIVE_API_UPLOAD_URL); var item = new GoogleDriveFolderItem() { title = remotename, description = remotename, mimeType = "application/octet-stream", labels = new GoogleDriveFolderItemLabels { hidden = true }, parents = new GoogleDriveParentReference[] { new GoogleDriveParentReference() { id = CurrentFolderId } } }; var res = GoogleCommon.ChunckedUploadWithResume <GoogleDriveFolderItem, GoogleDriveFolderItem>(m_oauth, item, url, stream, isUpdate ? "PUT" : "POST"); m_filecache[remotename] = new GoogleDriveFolderItem[] { res }; } catch { m_filecache.Clear(); throw; } }
public void Put(string remotename, System.IO.Stream stream) { try { // Figure out if we update or create the file if (m_filecache.Count == 0) { foreach (var file in List()) /* Enumerate the full listing */ } { } GoogleDriveFolderItem[] files; m_filecache.TryGetValue(remotename, out files); string fileId = null; if (files != null) { if (files.Length == 1) { fileId = files[0].id; } else { Delete(remotename); } } var isUpdate = !string.IsNullOrWhiteSpace(fileId); var url = WebApi.GoogleDrive.PutUrl(fileId); var item = new GoogleDriveFolderItem { title = remotename, description = remotename, mimeType = "application/octet-stream", labels = new GoogleDriveFolderItemLabels { hidden = true }, parents = new GoogleDriveParentReference[] { new GoogleDriveParentReference { id = CurrentFolderId } } }; var res = GoogleCommon.ChunckedUploadWithResume <GoogleDriveFolderItem, GoogleDriveFolderItem>(m_oauth, item, url, stream, isUpdate ? "PUT" : "POST"); m_filecache[remotename] = new GoogleDriveFolderItem[] { res }; } catch { m_filecache.Clear(); throw; } }
public void Put(string remotename, System.IO.Stream stream) { var item = new BucketResourceItem { name = m_prefix + remotename }; var url = WebApi.GoogleCloudStorage.PutUrl(m_bucket); var res = GoogleCommon.ChunckedUploadWithResume <BucketResourceItem, BucketResourceItem>(m_oauth, item, url, stream); if (res == null) { throw new Exception("Upload succeeded, but no data was returned"); } }
public void Put(string remotename, System.IO.Stream stream) { var url = string.Format("{0}/b/{1}/o?uploadType=resumable", UPLOAD_API_URL, m_bucket); var item = new BucketResourceItem() { name = m_prefix + remotename }; var res = GoogleCommon.ChunckedUploadWithResume <BucketResourceItem, BucketResourceItem>(m_oauth, item, url, stream); if (res == null) { throw new Exception(string.Format("Upload succeeded, but no data was returned")); } }