Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions Qiniu/IO/Resumable/ResumablePut.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
#if NET40
using System.Threading.Tasks;
#endif
using Qiniu.Auth;
using Qiniu.Conf;
using Qiniu.RPC;
using Qiniu.RS;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
#if NET40
using System.Threading.Tasks;
#endif
using Qiniu.Auth;
using Qiniu.Conf;
using Qiniu.RPC;
using Qiniu.RS;
using Qiniu.Util;

namespace Qiniu.IO.Resumable
Expand Down Expand Up @@ -77,14 +77,16 @@ public CallRet PutFile(string upToken, string localFile, string key)
throw new Exception(string.Format("{0} does not exist", localFile));
}

string fname = Path.GetFileName(localFile);

PutAuthClient client = new PutAuthClient(upToken);
CallRet ret;
using (FileStream fs = File.OpenRead(localFile))
{
int block_cnt = block_count(fs.Length);
long fsize = fs.Length;
extra.Progresses = new BlkputRet[block_cnt];
byte[] byteBuf = new byte[BLOCKSIZE];
byte[] byteBuf = new byte[BLOCKSIZE];
int readLen = BLOCKSIZE;
for (int i = 0; i < block_cnt; i++)
{
Expand All @@ -103,7 +105,7 @@ public CallRet PutFile(string upToken, string localFile, string key)
extra.OnNotify(new PutNotifyEvent(i, readLen, extra.Progresses[i]));
}
}
ret = Mkfile(client, key, fsize);
ret = Mkfile(client, key, fsize,fname);
}
if (ret.OK)
{
Expand Down Expand Up @@ -172,14 +174,18 @@ private BlkputRet Mkblock(Client client, byte[] firstChunk, int blkSize)
return null;
}

private CallRet Mkfile(Client client, string key, long fsize)
private CallRet Mkfile(Client client, string key, long fsize, string fname)
{
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.AppendFormat("{0}/mkfile/{1}", Config.UP_HOST, fsize);
if (key != null)
{
urlBuilder.AppendFormat("/key/{0}", Base64URLSafe.ToBase64URLSafe(key));
}
if (fname != null)
{
urlBuilder.AppendFormat("/fname/{0}", Base64URLSafe.ToBase64URLSafe(fname));
}
if (!string.IsNullOrEmpty(extra.MimeType))
{
urlBuilder.AppendFormat("/mimeType/{0}", Base64URLSafe.ToBase64URLSafe(extra.MimeType));
Expand Down Expand Up @@ -220,4 +226,4 @@ private int block_count(long fsize)
return (int)((fsize + blockMashk) >> blockBits);
}
}
}
}