Beispiel #1
0
        /// <summary>
        /// 上传从文件
        /// </summary>
        /// <param name="storageNode">GetStorageNode方法返回的存储节点</param>
        /// <param name="contentByte">文件内容</param>
        /// <param name="master_filename">主文件名</param>
        /// <param name="prefix_name">从文件后缀</param>
        /// <param name="fileExt">文件扩展名(注意:不包含".")</param>
        /// <returns>文件名</returns>
        public static string UploadSlaveFile(string groupName, byte[] contentByte, string master_filename, string prefix_name, string fileExt)
        {
            FDFSRequest trackerRequest = QUERY_UPDATE.Instance.GetRequest(groupName, master_filename);

            QUERY_UPDATE.Response trackerResponse = new QUERY_UPDATE.Response(trackerRequest.GetResponse());
            IPEndPoint            storeEndPoint   = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);

            FDFSRequest storageReqeust = UPLOAD_SLAVE_FILE.Instance.GetRequest(storeEndPoint, contentByte.Length, master_filename, prefix_name, fileExt, contentByte);

            UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response(storageReqeust.GetResponse());
            return(storageResponse.FileName);
        }
Beispiel #2
0
        /// <summary>
        /// 上传文件到FastDFS
        /// </summary>
        /// <param name="storageNode"></param>
        /// <param name="contentByte"></param>
        /// <param name="fileExt"></param>
        /// <param name="beginDelegate">上传前回调</param>
        /// <param name="afterDelegate">上传后回调,参数为URL文件名</param>
        /// <returns>返回短文件名</returns>
        public static string UploadFile(StorageNode storageNode, byte[] contentByte, string fileExt, System.Action <string> beginDelegate, System.Action <string> afterDelegate)
        {
            if (null != beginDelegate)
            {
                beginDelegate(fileExt);
            }

            FDFSRequest storageReqeust = UPLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, contentByte.Length, fileExt, contentByte);

            UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response(storageReqeust.GetResponse());

            if (null != afterDelegate)
            {
                afterDelegate(GetFormatUrl(storageNode.EndPoint.Address.ToString(), storageNode.GroupName, storageResponse.FileName));
            }

            return(storageResponse.FileName);
        }