You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.4 KiB
71 lines
2.4 KiB
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
using Newtonsoft.Json;
|
|
using Amazon;
|
|
using Amazon.S3;
|
|
using Amazon.Runtime;
|
|
using S3Demo.Helper;
|
|
using Ksat.Supplyment.Library.Uploader;
|
|
using Ksat.Logging;
|
|
|
|
namespace S3Demo.Model.Uploader
|
|
{
|
|
|
|
public class S3UploadRequest : IUploaderRequest<S3UploadModel>
|
|
{
|
|
|
|
// 通过固定域名的方式
|
|
//private static AmazonS3Config conf = new AmazonS3Config()
|
|
//{
|
|
// ServiceURL = "https://play.min.io",
|
|
// ForcePathStyle = true
|
|
//};
|
|
//new BasicAWSCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
|
|
public string bucketName = "minio/test";
|
|
public AmazonS3Client client = new AmazonS3Client(new BasicAWSCredentials("admin", "admin123."), new AmazonS3Config()
|
|
{
|
|
UseHttp = true,
|
|
ProxyHost = "http://192.168.60.132",
|
|
ProxyPort = 9000,
|
|
RegionEndpoint = RegionEndpoint.USEast1
|
|
});
|
|
private ILogger sLog = LoggerFactory.ForContext<S3UploadOperator>();
|
|
|
|
public S3UploadModel RequestData { get; set; }
|
|
|
|
public event UploadFinishHandler UploadFinish;
|
|
|
|
/// <summary>
|
|
/// Scada Api
|
|
/// </summary>
|
|
private static string url = "http://172.17.204.30:9000/api/tri/imagesupload";
|
|
|
|
public void Cancel()
|
|
{
|
|
mTask?.Dispose();
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
_ = objSend();
|
|
}
|
|
|
|
private Task<string> mTask;
|
|
public async Task objSend()
|
|
{
|
|
mTask = ObjectHelper.PutObjectsWithTagsAsync(client, bucketName, RequestData.Keyname, RequestData.Path, RequestData.Tags);
|
|
string res = await mTask;
|
|
UploadFinish(this, res.Equals("OK"), res);
|
|
//TODO: 请求接口,上传状态
|
|
ScadaRequest req = new ScadaRequest();
|
|
ScadaResponse resp = new ScadaResponse();
|
|
req.s3Flag = res;
|
|
req.dateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
|
|
resp = JsonConvert.DeserializeObject<ScadaResponse>(Helper.HttpHelper.PostUrl(url, JsonConvert.SerializeObject(req)));
|
|
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")} S3Recv {RequestData.Keyname} ==>{res}");
|
|
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")} ScadaRecv ==>{resp.code} & {resp.message}");
|
|
}
|
|
}
|
|
}
|