예제 #1
0
        public async Task <Dictionary <string, string> > GetJobInfo(string jobId)
        {
            var client = new HttpClient();
            var url    = "https://api2.online-convert.com/jobs/" + jobId;

            client.DefaultRequestHeaders.Add("x-oc-api-key", "744be7d281d6b3b6871baef24cf58052");
            var response = await client.GetAsync(url);

            var strResponse = await response.Content.ReadAsStringAsync();

            UploadOutput getJob = JsonConvert.DeserializeObject <UploadOutput>(strResponse);
            var          output = new Dictionary <string, string>();

            output["output"] = getJob.output[0].uri;
            return(output);
        }
        /// <summary>
        /// 上传文件的具体实现
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task <UploadOutput> UploadCoreAsync(UploadCoreInput input)
        {
            var output = new UploadOutput();
            //存入OSS的对象名称
            var objectName = $"{_ossConfig.ObjectNamePrefix}/{input.FileName}";

            try
            {
                using (MemoryStream ms = new MemoryStream(input.FileBytes))
                {
                    await Task.Run(() => {
                        var putResult = _ossClient.PutObject(_ossConfig.BucketName, objectName, ms);
                        if (putResult.HttpStatusCode == System.Net.HttpStatusCode.OK)
                        {
                            output.State    = "SUCCESS";
                            output.Url      = $"{(string.IsNullOrWhiteSpace(_ossConfig.CustomerDomain) ? $"{_ossConfig.BucketName}.{_ossConfig.EndPoint}/{objectName}" : $"{_ossConfig.CustomerDomain}/{objectName}")}";
                            output.Original = input.OriginalFileName;
                        }
                        else
                        {
                            throw new UEditorServiceException("上传至OSS失败", new StreamReader(putResult.ResponseStream, Encoding.UTF8).ReadToEnd());
                        }
                    });