* AVFileController.cs: fix: 修复上传文件的 bug

* AWSUploader.cs:
* QiniuUploader.cs:
oneRain 2019-08-26 16:31:17 +08:00
parent d339fe9e4e
commit 15e6a5d9c3
3 changed files with 9 additions and 13 deletions

View File

@ -85,11 +85,10 @@ namespace LeanCloud.Storage.Internal {
}); });
} }
internal static string GetUniqueName(FileState fileState) { internal static string GetUniqueName(FileState state) {
string key = Random(12); string key = Guid.NewGuid().ToString();
string extension = Path.GetExtension(fileState.Name); string extension = Path.GetExtension(state.Name);
key += extension; key += extension;
fileState.CloudName = key;
return key; return key;
} }

View File

@ -19,8 +19,11 @@ namespace LeanCloud.Storage.Internal {
} }
internal async Task<FileState> PutFile(FileState state, string uploadUrl, Stream dataStream) { internal async Task<FileState> PutFile(FileState state, string uploadUrl, Stream dataStream) {
IList<KeyValuePair<string, string>> makeBlockHeaders = new List<KeyValuePair<string, string>>(); IList<KeyValuePair<string, string>> makeBlockHeaders = new List<KeyValuePair<string, string>> {
makeBlockHeaders.Add(new KeyValuePair<string, string>("Content-Type", state.MimeType)); new KeyValuePair<string, string>("Content-Type", state.MimeType),
new KeyValuePair<string, string>("Cache-Control", "public, max-age=31536000"),
new KeyValuePair<string, string>("Content-Length", dataStream.Length.ToString())
};
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage { HttpRequestMessage request = new HttpRequestMessage {

View File

@ -29,7 +29,7 @@ namespace LeanCloud.Storage.Internal {
public Task<FileState> Upload(FileState state, Stream dataStream, IDictionary<string, object> fileToken, IProgress<AVUploadProgressEventArgs> progress, CancellationToken cancellationToken) { public Task<FileState> Upload(FileState state, Stream dataStream, IDictionary<string, object> fileToken, IProgress<AVUploadProgressEventArgs> progress, CancellationToken cancellationToken) {
state.frozenData = dataStream; state.frozenData = dataStream;
state.CloudName = GetUniqueName(state); state.CloudName = fileToken["key"] as string;
MergeFromJSON(state, fileToken); MergeFromJSON(state, fileToken);
return UploadNextChunk(state, dataStream, string.Empty, 0, progress).OnSuccess(_ => { return UploadNextChunk(state, dataStream, string.Empty, 0, progress).OnSuccess(_ => {
return state; return state;
@ -101,12 +101,6 @@ namespace LeanCloud.Storage.Internal {
return chunkBinary; return chunkBinary;
} }
internal string GetUniqueName(FileState state) {
string key = Guid.NewGuid().ToString();//file Key in Qiniu.
string extension = Path.GetExtension(state.Name);
key += extension;
return key;
}
internal Task<Tuple<HttpStatusCode, IDictionary<string, object>>> GetQiniuToken(FileState state, CancellationToken cancellationToken) { internal Task<Tuple<HttpStatusCode, IDictionary<string, object>>> GetQiniuToken(FileState state, CancellationToken cancellationToken) {
string str = state.Name; string str = state.Name;