Пример #1
0
        private static void UpLoadFile(UploadFileInfo info)
        {
            string key  = info.fileNmae;
            string file = info.filePath;

            string bucketFilePath = "/" + key;
            string url            = "http://" + host + bucketFilePath;

            Debug.Log("upload url = " + url);
            string contentMD5              = GetFileMD5(file);
            string contentType             = "application/octet-stream";
            string utcGMT                  = DateTime.UtcNow.ToString("r");
            string canonicalizedOSSHeaders = "";
            string canonicalizedResource   = "/sincebest-game-client/" + key;
            string authorization           = GetAuthorization("PUT", contentMD5, contentType, utcGMT, canonicalizedOSSHeaders, canonicalizedResource);

            Debug.Log("autorzation = " + authorization);


            Debug.LogError("12==== " + url);
            HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Put, true, OnRequestCallBack);

            request.OnUploadProgress = OnUploadProgress;
            request.UploadStream     = new FileStream(file, FileMode.Open);

            AbUpLoadInfo upLoadInfo = new AbUpLoadInfo();

            upLoadInfo.fileName = fileInfos[curUpLoadIndex].fileNmae;
            upLoadInfo.size     = (int)request.UploadStream.Length;
            upLoadInfo.filePath = url;
            finishMessage.infos.Add(upLoadInfo);

            request.AddHeader("Content-Encoding", "utf-8");
            request.AddHeader("Content-Md5", contentMD5);
            request.AddHeader("Content-Disposition", "attachment;filename=" + key);
            request.AddHeader("Date", utcGMT);
            request.AddHeader("Content-Length", request.UploadStream.Length.ToString());
            request.AddHeader("Host", host);
            request.AddHeader("Authorization", authorization);
            request.Send();
        }
Пример #2
0
        /// <summary>
        /// 全部上传成功回调
        /// fileList : key -> filename  value -> filepath
        /// callback : 上传完成后回调
        /// </summary>
        public static void UpLoadFiles(List <KeyValuePair <string, string> > fileList, OnUploadFinishDelegate callback = null)
        {
            if (fileList == null)
            {
                Debug.Log("error: Upload files = null");
                return;
            }
            Clear();
            waitingForUpLoad = true;

            foreach (var element in fileList)
            {
                UploadFileInfo info = new UploadFileInfo(element.Key, element.Value);
                fileInfos.Add(info);
            }

            if (fileInfos.Count > 0)
            {
                finishCallBack = callback;
                UpLoadFile(fileInfos[curUpLoadIndex]);
            }
        }