示例#1
0
        public async Task PutAsync(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
        {
            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, m_teamDriveID != null);

            var item = new GoogleDriveFolderItem
            {
                title       = remotename,
                description = remotename,
                mimeType    = "application/octet-stream",
                labels      = new GoogleDriveFolderItemLabels {
                    hidden = true
                },
                parents = new GoogleDriveParentReference[] { new GoogleDriveParentReference {
                                                                 id = CurrentFolderId
                                                             } },
                teamDriveId = m_teamDriveID
            };

            var res = await GoogleCommon.ChunkedUploadWithResumeAsync <GoogleDriveFolderItem, GoogleDriveFolderItem>(m_oauth, item, url, stream, cancelToken, isUpdate? "PUT" : "POST");

            m_filecache[remotename] = new GoogleDriveFolderItem[] { res };
        }
        catch
        {
            m_filecache.Clear();
            throw;
        }
    }
示例#2
0
        public async Task PutAsync(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
        {
            var item = new BucketResourceItem {
                name = m_prefix + remotename
            };

            var url = WebApi.GoogleCloudStorage.PutUrl(m_bucket);
            var res = await GoogleCommon.ChunkedUploadWithResumeAsync <BucketResourceItem, BucketResourceItem>(m_oauth, item, url, stream, cancelToken);

            if (res == null)
            {
                throw new Exception("Upload succeeded, but no data was returned");
            }
        }