/// 获取对象信息 public void HeadObject() { //.cssg-snippet-body-start:[head-object] try { string bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID string key = "exampleobject"; //对象键 HeadObjectRequest request = new HeadObjectRequest(bucket, key); //执行请求 HeadObjectResult result = cosXml.HeadObject(request); //请求成功 Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
public async Task <ItemMeta> GetObjectMetadataAsync(string bucketName, string objectName, string versionID = null, string matchEtag = null, DateTime?modifiedSince = null) { if (string.IsNullOrEmpty(bucketName)) { throw new ArgumentNullException(nameof(bucketName)); } if (string.IsNullOrEmpty(objectName)) { throw new ArgumentNullException(nameof(objectName)); } bucketName = ConvertBucketName(bucketName); HeadObjectRequest request = new HeadObjectRequest(bucketName, objectName); if (!string.IsNullOrEmpty(versionID)) { request.SetVersionId(versionID); } //执行请求 HeadObjectResult result = _client.HeadObject(request); if (!result.IsSuccessful()) { throw new Exception("Query object meta data failed."); } ItemMeta metaData = new ItemMeta() { ObjectName = objectName, Size = result.size, ETag = result.eTag, IsEnableHttps = Options.IsEnableHttps, }; return(await Task.FromResult(metaData)); }
public static void AsynHeadObject(COSXML.CosXml cosXml, string bucket, string key) { QLog.D("XIAO", String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); HeadObjectRequest request = new HeadObjectRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); cosXml.HeadObject(request, delegate(CosResult cosResult) { HeadObjectResult result = cosResult as HeadObjectResult; Console.WriteLine(result.GetResultInfo()); Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); }); }
public string SignHeadObject(string bucketName, string objectKey, TimeSpan expires, Action <HeadObjectRequest>?config = null) { HeadObjectRequest request = new HeadObjectRequest(bucketName, objectKey); config?.Invoke(request); return(_operations.SignHeadObject(request, expires)); }
public Task <HeadObjectResponse> HeadObjectAsync(string bucketName, string objectKey, Action <HeadObjectRequest>?config = null, CancellationToken token = default) { HeadObjectRequest req = new HeadObjectRequest(bucketName, objectKey); config?.Invoke(req); return(ObjectOperations.HeadObjectAsync(req, token)); }
public Task <HeadObjectResponse> HeadObjectAsync(string bucketName, string resource, Action <HeadObjectRequest> config = null, CancellationToken token = default) { HeadObjectRequest req = new HeadObjectRequest(bucketName, resource); config?.Invoke(req); return(_operations.HeadAsync(req, token)); }
public void TestHeadObject() { if (init()) { HeadObjectRequest headObjectRequest = new HeadObjectRequest(); headObjectRequest.BucketName = bucketName; headObjectRequest.ObjectKey = objKeyNameFileData; HeadObjectResult result = ks3Client.headObject(headObjectRequest); } }
/// <summary> /// オブジェクトヘッダを取得する /// </summary> /// <param name="nameSpaceName"></param> /// <param name="bucketName"></param> /// <param name="objectName"></param> /// <param name="regionName"></param> /// <returns></returns> public HeadObjectResponse GetObjectHead(string nameSpaceName, string bucketName, string objectName, string regionName) { ObjectStorageClient.SetRegion(regionName); HeadObjectRequest headObjectRequest = new HeadObjectRequest { NamespaceName = nameSpaceName, BucketName = bucketName, ObjectName = objectName }; return(ObjectStorageClient.HeadObject(headObjectRequest)); }
internal void Download() { UpdateTaskState(TaskState.Waiting); //对象是否存在 headObjectRequest = new HeadObjectRequest(bucket, key); cosXmlServer.HeadObject(headObjectRequest, delegate(CosResult cosResult) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.Running)) { HeadObjectResult result = cosResult as HeadObjectResult; ComputeSliceList(result); // resolv resumeInfo if (resumable) { if (resumableTaskFile == null) { resumableTaskFile = localDir + localFileName + ".cosresumabletask"; } ResumeDownloadInPossible(result, localDir + localFileName); } // concurrent download GetObject(result.crc64ecma); } }, delegate(CosClientException clientEx, CosServerException serverEx) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.Failed)) { if (failCallback != null) { failCallback(clientEx, serverEx); } } }); }
private bool CheckFileExists(string bucket, string fileKey) { try { HeadObjectRequest request = new HeadObjectRequest(bucket, fileKey); request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), COS_REQUEST_DEFAULT_DURATION); HeadObjectResult result = cosXml.HeadObject(request); return(result.httpCode.Equals(COS_STATUS.OK)); } catch (Exception ex) { return(false); } }
/// <summary> /// Querying whether a object exists. /// </summary> /// <param name="request">Parameters in a request for querying whether a object exists</param> /// <returns>Response to a request for querying whether a object exists</returns> public bool HeadObject(HeadObjectRequest request) { try { this.DoRequest <HeadObjectRequest, ObsWebServiceResponse>(request); return(true); } catch (ObsException e) { if (e.StatusCode == HttpStatusCode.NotFound) { return(false); } throw e; } }
internal void Download() { UpdateTaskState(TaskState.Waiting); //对象是否存在 headObjectRequest = new HeadObjectRequest(bucket, key); cosXmlServer.HeadObject(headObjectRequest, delegate(CosResult cosResult) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.Running)) { HeadObjectResult result = cosResult as HeadObjectResult; //计算range //download GetObject(); } }, delegate(CosClientException clientEx, CosServerException serverEx) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.Failed)) { if (failCallback != null) { failCallback(clientEx, serverEx); } } }); }
/// <summary> /// 获取文件信息 /// </summary> /// <param name="containerName"></param> /// <param name="blobName"></param> /// <returns></returns> public async Task <BlobFileInfo> GetBlobFileInfo(string containerName, string blobName) { var key = $"{containerName}/{blobName}"; var request = new HeadObjectRequest(_tcConfig.BucketName, key); var response = _cosXmlServer.HeadObject(request); await response.HandlerError("获取文件信息出错!"); return(new BlobFileInfo { Container = containerName, //ContentMD5 = response.Headers.ContentMD5, ContentType = response.responseHeaders.ContainsKey("Content-Type") ? (response.responseHeaders["Content-Type"].FirstOrDefault()) : null, ETag = response.eTag, Length = response.size, LastModified = response.responseHeaders.ContainsKey("Last-Modified") ? DateTime.Parse(response.responseHeaders["Last-Modified"].FirstOrDefault()) : (DateTime?)null, Name = blobName, Url = GetUrlByKey(key) }); }
internal void Download() { UpdateTaskState(TaskState.WAITTING); //对象是否存在 headObjectRequest = new HeadObjectRequest(bucket, key); headObjectRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); cosXmlServer.HeadObject(headObjectRequest, delegate(CosResult cosResult) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.RUNNING)) { HeadObjectResult result = cosResult as HeadObjectResult; //计算range //download GetObject(); } }, delegate(CosClientException clientEx, CosServerException serverEx) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.FAILED)) { if (failCallback != null) { failCallback(clientEx, serverEx); } } }); }
public static bool headObject() { try { Console.WriteLine("--- headObject: ---"); HeadObjectRequest headObjectRequest = new HeadObjectRequest(); headObjectRequest.BucketName = bucketName; headObjectRequest.ObjectKey = objKeyNameFileData; HeadObjectResult result = ks3Client.headObject(headObjectRequest); long length = result.ObjectMetadata.getContentLength(); Console.WriteLine("---------------------\n"); } catch (System.Exception e) { Console.WriteLine(e.ToString()); return(false); } return(true); }
public void HeadObject() { try { HeadObjectRequest request = new HeadObjectRequest(bucket, commonKey); //执行请求 HeadObjectResult result = cosXml.HeadObject(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.StackTrace); Assert.True(false); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.True(false); } }
public async Task FullPreSignTest() { int expireIn = 100; PutObjectRequest putReq = new PutObjectRequest(BucketName, "test.zip", null); string url = PreSignedObjectClient.SignPutObjectRequest(putReq, TimeSpan.FromSeconds(expireIn)); using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes("hello world"))) { PutObjectResponse?putResp = await PreSignedObjectClient.PutObjectAsync(url, ms).ConfigureAwait(false); Assert.Equal(200, putResp.StatusCode); } GetObjectRequest getReq = new GetObjectRequest(BucketName, "test.zip"); url = PreSignedObjectClient.SignGetObjectRequest(getReq, TimeSpan.FromSeconds(expireIn)); GetObjectResponse?getResp = await PreSignedObjectClient.GetObjectAsync(url).ConfigureAwait(false); Assert.Equal(200, getResp.StatusCode); DeleteObjectRequest req = new DeleteObjectRequest(BucketName, "test.zip"); url = PreSignedObjectClient.SignDeleteObjectRequest(req, TimeSpan.FromSeconds(expireIn)); DeleteObjectResponse deleteResp = await PreSignedObjectClient.DeleteObjectAsync(url).ConfigureAwait(false); Assert.Equal(204, deleteResp.StatusCode); HeadObjectRequest headReq = new HeadObjectRequest(BucketName, "test.zip"); url = PreSignedObjectClient.SignHeadObjectRequest(headReq, TimeSpan.FromSeconds(expireIn)); HeadObjectResponse headResp = await PreSignedObjectClient.HeadObjectAsync(url).ConfigureAwait(false); Assert.Equal(404, headResp.StatusCode); }
public static void HeadObject(COSXML.CosXml cosXml, string bucket, string key) { try { HeadObjectRequest request = new HeadObjectRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 HeadObjectResult result = cosXml.HeadObject(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public Task <HeadObjectResponse> HeadAsync(HeadObjectRequest request, CancellationToken token = default) { return(_requestHandler.SendRequestAsync <HeadObjectRequest, HeadObjectResponse>(request, token)); }
public string SignHeadObjectRequest(HeadObjectRequest request, TimeSpan expires) { return(PreSignedObjectOperations.SignHeadObject(request, expires)); }
public async IAsyncEnumerable <GetObjectResponse> MultipartDownloadAsync(string bucketName, string resource, Stream output, int bufferSize = 16777216, int numParallelParts = 4, Action <GetObjectRequest> config = null, [EnumeratorCancellation] CancellationToken token = default) { Validator.RequireNotNull(output); //Use a HEAD request on the resource to determine if the file was originally uploaded with multipart HeadObjectRequest headReq = new HeadObjectRequest(bucketName, resource); headReq.PartNumber = 1; HeadObjectResponse headResp = await HeadAsync(headReq, token).ConfigureAwait(false); Queue <Task <GetObjectResponse> > queue = new Queue <Task <GetObjectResponse> >(); if (headResp.NumberOfParts == null) { GetObjectRequest getReq = new GetObjectRequest(bucketName, resource); config?.Invoke(getReq); GetObjectResponse getResp = await GetAsync(getReq, token).ConfigureAwait(false); if (!getResp.IsSuccess) { throw new Exception(); } await getResp.Content.CopyToAsync(output, token : token).ConfigureAwait(false); yield return(getResp); } else { int parts = headResp.NumberOfParts.Value; using (SemaphoreSlim semaphore = new SemaphoreSlim(numParallelParts)) using (Mutex mutex = new Mutex()) { for (int i = 1; i <= parts; i++) { await semaphore.WaitAsync(token).ConfigureAwait(false); if (token.IsCancellationRequested) { yield break; } queue.Enqueue(DownloadPartAsync(bucketName, resource, output, headResp.ContentLength, i, bufferSize, semaphore, mutex, token, config)); } while (queue.TryDequeue(out Task <GetObjectResponse> task)) { if (token.IsCancellationRequested) { yield break; } GetObjectResponse response = await task.ConfigureAwait(false); yield return(response); } } } }
public HeadObjectResult HeadObject(HeadObjectRequest request) { return((Model.Object.HeadObjectResult)Excute(request, new Model.Object.HeadObjectResult())); }
public void HeadObject(HeadObjectRequest request, Callback.OnSuccessCallback <CosResult> successCallback, Callback.OnFailedCallback failCallback) { Schedue(request, new HeadObjectResult(), successCallback, failCallback); }
/// <summary> /// Start the asynchronous request for querying whether a object exists. /// </summary> /// <param name="request">Parameters in a request for querying whether a object exists</param> /// <param name="callback">Asynchronous request callback function</param> /// <param name="state">Asynchronous request status object</param> /// <returns>Response to the asynchronous request</returns> public IAsyncResult BeginHeadObject(HeadObjectRequest request, AsyncCallback callback, object state) { return(this.BeginDoRequest <HeadObjectRequest>(request, callback, state)); }
public void TestHeadObject() { if (init()) { HeadObjectRequest headObjectRequest = new HeadObjectRequest(); headObjectRequest.BucketName = bucketName; headObjectRequest.ObjectKey = objKeyNameFileData; HeadObjectResult result = ks3Client.headObject(headObjectRequest); } }
public string SignHeadObject(HeadObjectRequest request, TimeSpan expiresIn) { return(_signedHandler.SignRequest(request, expiresIn)); }
public HeadObjectResponse HeadObject(HeadObjectRequest request) { return(new HeadObjectResponseParser().Parse(request, _netLayer.Invoke(request))); }
internal void Copy() { UpdateTaskState(TaskState.WAITTING); //源对象是否存在 if (copySource == null) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.FAILED)) { if (failCallback != null) { failCallback(new CosClientException((int)CosClientError.INVALID_ARGUMENT, "copySource = null"), null); } } //error return; } headObjectRequest = new HeadObjectRequest(copySource.bucket, copySource.key); headObjectRequest.Region = copySource.region; cosXmlServer.HeadObject(headObjectRequest, delegate(CosResult cosResult) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.RUNNING)) { HeadObjectResult result = cosResult as HeadObjectResult; //源对象的长度 sourceSize = result.size; if (sourceSize > divisionSize) { MultiPartCopy(); } else { SimpleCopy(); } } }, delegate(CosClientException clientEx, CosServerException serverEx) { lock (syncExit) { if (isExit) { return; } } if (UpdateTaskState(TaskState.FAILED)) { if (failCallback != null) { failCallback(clientEx, serverEx); } } }); }