Merge pull request #89 from onerain88/file_upload_callback

chore: 支持文件上传结果回调 API
oneRain 2020-08-17 13:28:52 +08:00 committed by GitHub
commit bf3e690618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 12 deletions

View File

@ -79,19 +79,31 @@ namespace LeanCloud.Storage {
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;
}