diff --git a/Qiniu/IO/Resumable/ResumablePut.cs b/Qiniu/IO/Resumable/ResumablePut.cs index b6ed3777..e5578f9a 100644 --- a/Qiniu/IO/Resumable/ResumablePut.cs +++ b/Qiniu/IO/Resumable/ResumablePut.cs @@ -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 @@ -77,6 +77,8 @@ 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)) @@ -84,7 +86,7 @@ public CallRet PutFile(string upToken, string localFile, string key) 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++) { @@ -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) { @@ -172,7 +174,7 @@ 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); @@ -180,6 +182,10 @@ private CallRet Mkfile(Client client, string key, long fsize) { 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)); @@ -220,4 +226,4 @@ private int block_count(long fsize) return (int)((fsize + blockMashk) >> blockBits); } } -} +}