Example #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();
        }
Example #2
0
        public static void OnRequestCallBack(HTTPRequest request, HTTPResponse response)
        {
            AbUpLoadInfo info = finishMessage.infos.Find((a) => a.fileName == fileInfos[curUpLoadIndex].fileNmae);

            info.isSuccess = response.IsSuccess;
            info.errormsg  = response.DataAsText;

            Debug.LogError("12==Finish upload " + info.fileName + ", path = " + info.filePath + ", size = " + info.size + ", isSuccess = " + info.isSuccess);
            Debug.LogError("13==errormsg = " + info.errormsg);



            curUpLoadIndex++;
            if (curUpLoadIndex >= fileInfos.Count)
            {
                DoAction();
            }
            else
            {
                UpLoadFile(fileInfos[curUpLoadIndex]);
            }
        }