Example #1
0
 public static string UploadExecute(byte[] buffer, string FileName, ApplicationKeyType applicationKeyType)
 {
     string valueByCache = ConfigSystem.GetValueByCache(applicationKeyType + "_YouPaiYunOperaterName");
     string password = ConfigSystem.GetValueByCache(applicationKeyType + "_YouPaiOperaterPassword");
     string bucketname = ConfigSystem.GetValueByCache(applicationKeyType + "_YouPaiSpaceName");
     string str4 = ConfigSystem.GetValueByCache(applicationKeyType + "_YouPaiPhotoDomain");
     UpYun yun = new UpYun(bucketname, valueByCache, password);
     byte[] data = buffer;
     string path = "/" + DateTime.Now.ToString("yyyyMMdd") + "/" + FileName;
     if (yun.writeFile(path, data, true))
     {
         return (str4 + path);
     }
     return "";
 }
Example #2
0
 public void UploadFile(ArrayList uploadFileNameList, string localPath, string remotePath, bool isRecursive)
 {
     foreach (string fileName in uploadFileNameList)
     {
         string fileLocalPath  = Path.Combine(localPath, fileName);
         string fileRemotePath = SFUCommon.CombinePath4Web(remotePath, fileName);
         bool   isDirectory    = Directory.Exists(fileLocalPath);
         if (isDirectory)
         {
             // TODO: If the item is folder, need to traverse folder recursively(Get all file path in the folder).
         }
         else
         {
             FileStream   fileStream   = new FileStream(fileLocalPath, FileMode.Open, FileAccess.Read);
             BinaryReader binaryReader = new BinaryReader(fileStream);
             byte[]       postByte     = binaryReader.ReadBytes((int)fileStream.Length);
             upYun.writeFile(fileRemotePath, postByte, isRecursive);
         }
     }
 }
        private async Task GetHttpWebRequestForAnYaAsync(string type)
        {
            string url = "";

            if (type.Equals("少女映画"))
            {
                url = "https://api.r10086.com:8443/少女映画.php?password=20";
            }
            else
            {
                url = $"https://api.r10086.com:8443/" + type + ".php";
            }
            //建立请求
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            //添加Referer信息
            request.Headers.Add(HttpRequestHeader.Referer, "http://www.bz08.cn/");
            //伪装成谷歌浏览器
            //request.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
            request.Headers.Add(HttpRequestHeader.UserAgent, "I am a cute web crawler");
            //添加cookie认证信息
            Cookie cookie = new Cookie("PHPSESSID", "s9gajue8h7plf7n5ab8fehiuoq");

            cookie.Domain = "api.r10086.com";
            if (request.CookieContainer == null)
            {
                request.CookieContainer = new CookieContainer();
            }
            request.CookieContainer.Add(cookie);
            //发送请求获取Http响应
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            //HttpWebResponse response = (HttpWebResponse)(await request.GetResponseAsync().ConfigureAwait(false));

            var originalString = response.ResponseUri.OriginalString;

            Console.WriteLine(originalString);
            //获取响应流
            Stream receiveStream = response.GetResponseStream();
            //获取响应流的长度
            int length = (int)response.ContentLength;
            //读取到内存
            MemoryStream stmMemory = new MemoryStream();

            byte[] buffer1 = new byte[length];
            int    i;

            //将字节逐个放入到Byte 中
            while ((i = receiveStream.Read(buffer1, 0, buffer1.Length)) > 0)
            {
                stmMemory.Write(buffer1, 0, i);
            }

            //写入磁盘
            string name = System.IO.Path.GetFileName(originalString);

            byte[] imageBytes = stmMemory.ToArray();
            string fileSHA1   = SHAEncrypt_Helper.Hash1Encrypt(imageBytes);

            //上传到又拍云
            if (!RandomImageService.Exist(type, fileSHA1))
            {
                upyun.writeFile($"/upload/{SHAEncrypt_Helper.MD5Encrypt(type)}/{fileSHA1}{Path.GetExtension(name)}", imageBytes, true);
                RandomImage randomImage = new RandomImage()
                {
                    RandomImageId = SnowFlake_Net.GenerateSnowFlakeID(),
                    TypeName      = type,
                    TypeNameMD5   = SHAEncrypt_Helper.MD5Encrypt(type),
                    TypeNameSHA1  = SHAEncrypt_Helper.Hash1Encrypt(type),
                    FileName      = name,
                    FileNameMD5   = SHAEncrypt_Helper.MD5Encrypt(name),
                    FileNameSHA1  = SHAEncrypt_Helper.Hash1Encrypt(name),
                    FileSHA1      = fileSHA1,
                    Sex           = false,
                };
                //记录到数据库
                await RandomImageService.InsertImageAsync(randomImage).ConfigureAwait(false);
            }

            //name = $"{dir}{dsc}upload{dsc}{type}{dsc}{name}";
            //if (!Directory.Exists($"{dir}{dsc}upload{dsc}{type}"))
            //{
            //    Directory.CreateDirectory($"{dir}{dsc}upload{dsc}{type}");
            //}
            //if (!System.IO.File.Exists(name))
            //{
            //    FileStream file = new FileStream(name, FileMode.Create, FileAccess.ReadWrite);
            //    file.Write(stmMemory.ToArray());
            //    file.Flush();
            //    file.Close();
            //}
            //FileStream file = new FileStream("1.jpg",FileMode.Create, FileAccess.ReadWrite);
            //关闭流
            stmMemory.Close();
            receiveStream.Close();
            response.Close();
        }