Skip to content

Commit

Permalink
chore: 支持文件上传结果回调 API
Browse files Browse the repository at this point in the history
  • Loading branch information
onerain88 committed Aug 17, 2020
1 parent 3aaa14c commit 4501dbb
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions Storage/Storage/LCFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,31 @@ public async Task<LCFile> Save(Action<long, long> onProgress = null) {
string key = uploadToken["key"] as string;
string token = uploadToken["token"] as string;
string provider = uploadToken["provider"] as string;
if (provider == "s3") {
// AWS
LCAWSUploader uploader = new LCAWSUploader(uploadUrl, MimeType, data);
await uploader.Upload(onProgress);
} else if (provider == "qiniu") {
// Qiniu
LCQiniuUploader uploader = new LCQiniuUploader(uploadUrl, token, key, data);
await uploader.Upload(onProgress);
} else {
throw new Exception($"{provider} is not support.");
try {
if (provider == "s3") {
// AWS
LCAWSUploader uploader = new LCAWSUploader(uploadUrl, MimeType, data);
await uploader.Upload(onProgress);
} else if (provider == "qiniu") {
// Qiniu
LCQiniuUploader uploader = new LCQiniuUploader(uploadUrl, token, key, data);
await uploader.Upload(onProgress);
} else {
throw new Exception($"{provider} is not support.");
}
LCObjectData objectData = LCObjectData.Decode(uploadToken);
Merge(objectData);
_ = LCApplication.HttpClient.Post<Dictionary<string, object>>("fileCallback", data: new Dictionary<string, object> {
{ "result", true },
{ "token", token }
});
} catch (Exception e) {
_ = LCApplication.HttpClient.Post<Dictionary<string, object>>("fileCallback", data: new Dictionary<string, object> {
{ "result", false },
{ "token", token }
});
throw e;
}
LCObjectData objectData = LCObjectData.Decode(uploadToken);
Merge(objectData);
}
return this;
}
Expand Down

0 comments on commit 4501dbb

Please sign in to comment.