/// <summary> /// 复制单个文件 /// </summary> /// <param name="source">原文件路径</param> /// <param name="destination">目标文件路径</param> /// <param name="ondup">同名覆盖方式</param> /// <returns>返回是否成功</returns> public bool CopyPath(string source, string destination, ondup ondup = ondup.overwrite) { if (_enable_function_trace) { _trace.TraceInfo("BaiduPCS.CopyPath called: string source=" + source + ", string destination=" + destination + ", ondup ondup=" + ondup); } return(CopyPath(new string[] { source }, new string[] { destination }, ondup)); }
/// <summary> /// 从输入流中读取数据并上传 /// </summary> /// <param name="stream_in">能读取的输入流</param> /// <param name="content_length">文件长度</param> /// <param name="path">网盘文件路径</param> /// <param name="ondup">同名覆盖方式</param> /// <param name="callback">读取进度回调函数</param> /// <returns></returns> public ObjectMetadata UploadRaw(Stream stream_in, ulong content_length, string path, ondup ondup = ondup.overwrite, UploadStatusCallback callback = null) { if (_enable_function_trace) { _trace.TraceInfo("BaiduPCS.UploadRaw called: Stream stream_in=" + stream_in.ToString() + ", ulong content_length=" + content_length + ", string path=" + path + ", ondup ondup=" + ondup + ", UploadStatusCallback callback=" + callback?.ToString()); } ObjectMetadata ret = new ObjectMetadata(); var set_event = new ManualResetEventSlim(); Guid task_id; UploadBeginAsync(content_length, path, (suc, id, data, s) => { try { task_id = id; var buffer = new byte[BUFFER_SIZE]; long total = 0; int cur = 0; do { cur = stream_in.Read(buffer, 0, (int)Math.Min(BUFFER_SIZE, (long)content_length - total)); data.Write(buffer, 0, cur); total += cur; callback?.Invoke(path, null, total, (long)content_length); } while (cur > 0); UploadEndAsync(id, (suc2, data2, s2) => { ret = data2; set_event.Set(); }); } catch (Exception ex) { _trace.TraceError(ex); set_event.Set(); } }, ondup); set_event.Wait(); return(ret); }
/// <summary> /// 秒传文件,失败时返回fs_id为0 /// </summary> /// <param name="path">路径</param> /// <param name="content_length">文件大小</param> /// <param name="content_md5">文件总体MD5</param> /// <param name="content_crc">文件总体CRC32 (Hex数值)</param> /// <param name="slice_md5">前256K验证段的MD5</param> /// <param name="ondup">同名覆盖方式</param> /// <returns>返回文件信息</returns> public ObjectMetadata RapidUploadRaw(string path, ulong content_length, string content_md5, string content_crc, string slice_md5, ondup ondup = ondup.overwrite) { if (_enable_function_trace) { _trace.TraceInfo("BaiduPCS.RapidUploadRaw called: string path=" + path + ", ulong content_length=" + content_length + ", string content_md5=" + content_md5 + ", string content_crc=" + content_crc + ", string slice_md5=" + slice_md5 + ", ondup ondup=" + ondup); } var set_event = new ManualResetEventSlim(); ObjectMetadata ret = new ObjectMetadata(); RapidUploadAsync(path, content_length, content_md5, content_crc, slice_md5, (suc, data, s) => { ret = data; set_event.Set(); }, ondup); set_event.Wait(); return(ret); }
/// <summary> /// 复制多个文件 /// </summary> /// <param name="source">原文件路径</param> /// <param name="destination">目标文件路径</param> /// <param name="ondup">同名覆盖方式</param> /// <returns>返回是否成功</returns> public bool CopyPath(IEnumerable <string> source, IEnumerable <string> destination, ondup ondup = ondup.overwrite) { if (_enable_function_trace) { _trace.TraceInfo("BaiduPCS.CopyPath called: IEnumerable<string> source=[count=" + source.Count() + "], IEnumerable<string> destination=[count=" + destination.Count() + "], ondup ondup=" + ondup); } var set_event = new ManualResetEventSlim(); bool ret = false; CopyPathAsync(source, destination, (suc, data, s) => { ret = data; set_event.Set(); }, ondup); set_event.Wait(); return(ret); }