public static void AsyncCopyObject(string sourceBucket, string sourceKey, string targetBucket, string targetKey) { try { var metadata = new ObjectMetadata(); metadata.AddHeader("mk1", "mv1"); metadata.AddHeader("mk2", "mv2"); var req = new CopyObjectRequest(sourceBucket, sourceKey, targetBucket, targetKey) { NewObjectMetadata = metadata }; client.BeginCopyObject(req, CopyObjectCallback, null); _event.WaitOne(); } catch (OssException ex) { Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); } catch (Exception ex) { Console.WriteLine("Failed with error info: {0}", ex.Message); } }
public async Task <bool> CopyFileAsync(string path, string targetPath, CancellationToken cancellationToken = default) { if (String.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (String.IsNullOrEmpty(targetPath)) { throw new ArgumentNullException(nameof(targetPath)); } try { var copyResult = await Task.Factory.FromAsync( (request, callback, state) => _client.BeginCopyObject(request, callback, state), result => _client.EndCopyResult(result), new CopyObjectRequest(_bucket, NormalizePath(path), _bucket, NormalizePath(targetPath)), null ).AnyContext(); return(copyResult.HttpStatusCode == HttpStatusCode.OK); } catch (Exception) { return(false); } }