Пример #1
0
        public static Tuple <bool, string> UpdateLoadImage(this byte[] buffer)
        {
            using (var client = new Tuhu.Service.Utility.FileUploadClient())
            {
                string dirName = swc.WebConfigurationManager.AppSettings["UploadDoMain_image"];

                var result = client.UploadImage(new ImageUploadRequest(dirName, buffer));
                result.ThrowIfException(true);
                if (result.Success)
                {
                    string imgUrl = swc.WebConfigurationManager.AppSettings["DoMain_image"] + result.Result;

                    return(Tuple.Create(true, imgUrl));
                }
                else
                {
                    return(Tuple.Create(false, result.Exception.ToString()));
                }
            }
        }
Пример #2
0
    public override void Process()
    {
        byte[] uploadFileBytes = null;
        string uploadFileName  = null;

        if (UploadConfig.Base64)
        {
            uploadFileName = UploadConfig.Base64Filename;

            uploadFileBytes = Convert.FromBase64String(Request[UploadConfig.UploadFieldName]);
        }
        else
        {
            var file = Request.Files[UploadConfig.UploadFieldName];
            uploadFileName = file.FileName;

            if (!CheckFileType(uploadFileName))
            {
                Result.State = UploadState.TypeNotAllow;
                WriteResult();
                return;
            }
            if (!CheckFileSize(file.ContentLength))
            {
                Result.State = UploadState.SizeLimitExceed;
                WriteResult();
                return;
            }

            uploadFileBytes = new byte[file.ContentLength];
            try
            {
                file.InputStream.Read(uploadFileBytes, 0, file.ContentLength);
            }
            catch (Exception)
            {
                Result.State = UploadState.NetworkError;
                WriteResult();
            }
        }

        Result.OriginFileName = uploadFileName;

        try
        {
            using (var client = new Tuhu.Service.Utility.FileUploadClient())
            {
                var result = client.UploadImage(new ImageUploadRequest(swc.WebConfigurationManager.AppSettings["UploadDoMain_image"], uploadFileBytes, 1000));

                result.ThrowIfException(true);

                Result.Url = swc.WebConfigurationManager.AppSettings["DoMain_image"] + result.Result;
            }

            Result.State = UploadState.Success;
        }
        catch (Exception e)
        {
            Result.State        = UploadState.FileAccessError;
            Result.ErrorMessage = e.Message;
        }
        finally
        {
            WriteResult();
        }
    }