From d86ab95cc1ff155b29c92bc801f20380316fc229 Mon Sep 17 00:00:00 2001 From: ZGGSONG Date: Fri, 10 Dec 2021 18:38:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KsatSupplymentLibrary/Uploader/Uploader.cs | 2 +- S3Demo/Helper/ObjectHelper.cs | 21 +++++++++++++++++---- S3Demo/Model/Uploader/S3UploadRequest.cs | 7 +++---- S3Demo/Program.cs | 7 +++++-- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/KsatSupplymentLibrary/Uploader/Uploader.cs b/KsatSupplymentLibrary/Uploader/Uploader.cs index e802592..aa1b272 100644 --- a/KsatSupplymentLibrary/Uploader/Uploader.cs +++ b/KsatSupplymentLibrary/Uploader/Uploader.cs @@ -152,7 +152,7 @@ namespace Ksat.Supplyment.Library.Uploader private void Req_OnRequestFinished(object sender, bool success, string reason) { var request = sender as IUploaderRequest; - var x = (request.RequestData); + var x = request.RequestData; var reqModel = dequeRequest(request); if (reqModel == null) diff --git a/S3Demo/Helper/ObjectHelper.cs b/S3Demo/Helper/ObjectHelper.cs index 3014f7c..cc5d0ee 100644 --- a/S3Demo/Helper/ObjectHelper.cs +++ b/S3Demo/Helper/ObjectHelper.cs @@ -27,12 +27,26 @@ namespace S3Demo.Helper /// object to be tagged. /// The directory location and file name of the /// object to be uploaded to the S3 bucket. - public static async Task PutObjectsWithTagsAsync(IAmazonS3 client, string bucketName, string keyName, string filePath, string[] tags) + public static async Task PutObjectsWithTagsAsync(IAmazonS3 client, string bucketName, string keyName, string filePath, List tags) { try { // Create an object with tags. - var putRequest = new PutObjectRequest + //List keys = new List { "sn", "date", "code" }; + //var putRequest = new PutObjectRequest() + //{ + // BucketName = bucketName, + // Key = keyName, + // FilePath = filePath + //}; + //for (int i = 0; i < tags.Count; i++) + //{ + // //TODO: 优化添加标签参数细节 + // putRequest.TagSet = new List { + // new Tag { Key = keys[i], Value = tags[i] } + // }; + //} + var putRequest = new PutObjectRequest() { BucketName = bucketName, Key = keyName, @@ -45,7 +59,6 @@ namespace S3Demo.Helper //new Tag { Key = "code", Value = tags[2] } }, }; - PutObjectResponse response = await client.PutObjectAsync(putRequest); //Console.WriteLine(putRequest.Key + "," + putRequest.BucketName + "," + putRequest.FilePath + "," + response.HttpStatusCode); return response.HttpStatusCode.ToString(); @@ -97,7 +110,7 @@ namespace S3Demo.Helper } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + //Console.WriteLine($"Error: {ex.Message}"); return ex.Message.ToString(); } } diff --git a/S3Demo/Model/Uploader/S3UploadRequest.cs b/S3Demo/Model/Uploader/S3UploadRequest.cs index 26a9839..706eca6 100644 --- a/S3Demo/Model/Uploader/S3UploadRequest.cs +++ b/S3Demo/Model/Uploader/S3UploadRequest.cs @@ -37,8 +37,8 @@ namespace S3Demo.Model.Uploader public void Cancel() { - mTask?.Dispose(); //TODO: + mTask?.Dispose(); } public void Start() @@ -50,11 +50,10 @@ namespace S3Demo.Model.Uploader private Task mTask; public async Task objSend() { - Console.WriteLine("==开始上传=="); - mTask = ObjectHelper.PutObjectsWithTagsAsync(client, bucketName, RequestData.Keyname, RequestData.Path, RequestData.Tags.ToArray()); + mTask = ObjectHelper.PutObjectsWithTagsAsync(client, bucketName, RequestData.Keyname, RequestData.Path, RequestData.Tags); string res = await mTask; UploadFinish(this, res.Equals("OK"), res); - Console.WriteLine($"S3 Upload recv: {res}"); + Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")} s3Recv {RequestData.Keyname}==>{res}"); } } } diff --git a/S3Demo/Program.cs b/S3Demo/Program.cs index e6c8857..31d868f 100644 --- a/S3Demo/Program.cs +++ b/S3Demo/Program.cs @@ -3,6 +3,7 @@ using System.IO; using S3Demo.Model.Uploader; using System.Threading; using System.Linq; +using System.Collections.Generic; namespace S3Demo { @@ -179,10 +180,12 @@ namespace S3Demo string dt_fomat = DateTime.ParseExact(datetime, "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd HH:mm:ss:fff"); string sn = fileName.Substring(9, 14); string now = DateTime.Now.ToString("yyyyMMddHHmmssfff"); - String[] tags = new String[] { sn, dt_fomat }; + List tags = new List(); + tags.Add(sn); + tags.Add(dt_fomat); string S3Path = lineName + "/" + equipmentName + "/" + date + "/" + fileName; - var uploadModel = new S3UploadModel { Keyname = S3Path, Path = path, Tags = tags.ToList() }; + var uploadModel = new S3UploadModel { Keyname = S3Path, Path = path, Tags = tags }; S3Uploader.Instance().AddUploadTask(uploadModel, sn); }