public string FileUpload()
        {
            var files = HttpContext.Current.Request.Files;
            if (files.Count == 0)
            {
                return "0";
            }

            var filename = string.Concat("card_logo_", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
            var filepath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "TempFile\\", filename, ".jpg");

            try
            {
                files[0].SaveAs(filepath);

                //上传图片到七牛云
                var qinniu = new QiniuUtility();
                var qrcodeKey = qinniu.PutFile(filepath, "", filename);

                //删除本地临时文件
                if (File.Exists(filepath))
                {
                    File.Delete(filepath);
                }

                return qrcodeKey;
            }
            catch (Exception ex)
            {
                return "-2";
            }
        }
Example #2
0
        public string FileUpload(string type)
        {
            var files = HttpContext.Current.Request.Files;
            if (files.Count == 0)
            {
                return "0";
            }

            try
            {
                var keys = "";
                for (var i = 0;i < files.Count; i++)
                {
                    var filename = string.Concat(type + "_", DateTime.Now.ToString("yyyyMMddHHmmssfff"), ".jpg");
                    var filepath = QiniuUtility.GetFilePath(filename);

                    files[i].SaveAs(filepath);

                    //上传图片到七牛云
                    var qinniu = new QiniuUtility();
                    var qrcodeKey = qinniu.PutFile(filepath, "", filename);

                    //删除本地临时文件
                    if (File.Exists(filepath))
                    {
                        File.Delete(filepath);
                    }

                    keys += qrcodeKey + ",";
                }

                return keys.TrimEnd(',');
            }
            catch (Exception ex)
            {
                LoggerFactories.CreateLogger().Write("上傳文件異常:", TraceEventType.Error, ex);
                return "-2";
            }
        }