Ejemplo n.º 1
0
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="postedFile">上传的文件对象</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <returns></returns>
        public static FileMessage UploadFile(HttpPostedFileBase postedFile, string key, out FileInfor fileInfor)
        {
            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;

            fileInfor = new FileInfor();


            //TODO: 增加contenttype的读取。
            FileMessage f = client.GetFileName(key, postedFile.ContentLength, postedFile.FileName, out fileKey, out fileExt);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName    = fileKey;
                    fileInfor.FileSize    = postedFile.ContentLength;
                    fileInfor.FileExtName = fileExt;
                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName   = fileKey;
                    inValue.KeyName    = key;
                    inValue.FileExt    = fileExt;
                    inValue.SaveOrigin = true;

                    if (postedFile.InputStream.CanRead)
                    {
                        //byte[] content = new byte[postedFile.ContentLength + 1];
                        //postedFile.InputStream.Read(content, 0, postedFile.ContentLength);
                        //inValue.FileData = new MemoryStream(content);
                        inValue.FileData = postedFile.InputStream;
                        client.UploadFile(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return(FileMessage.UnknowError);
                    }

                    return(FileMessage.Success);
                }
                catch
                {
                    return(FileMessage.UnknowError);
                }
            }
            else
            {
                return(f);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="postedFile">上传的文件对象</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <param name="userId">用户编号</param>
        /// <returns></returns>
        public static FileMessage UploadFile(HttpPostedFileBase postedFile, string key, out FileInfor fileInfor, int userId)
        {
            string useridstr = userId.ToString();

            if (useridstr.Length < 9)
            {
                for (int i = 0; i < (9 - useridstr.Length); i++)
                {
                    useridstr = "0" + useridstr;
                }
            }

            string[] folders = new string[2];
            folders[0] = useridstr.Substring(0, 3);
            folders[1] = useridstr.Substring(3, 3);

            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;

            fileInfor = new FileInfor();

            FileMessage f = client.GetFileNameByUser(key, postedFile.ContentLength, postedFile.FileName, null, out fileKey, out fileExt, folders);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName = fileKey;
                    fileInfor.FileSize = postedFile.ContentLength;

                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName   = fileKey;
                    inValue.KeyName    = key;
                    inValue.FileExt    = fileExt;
                    inValue.SaveOrigin = true;

                    if (postedFile.InputStream.CanRead)
                    {
                        //byte[] content = new byte[postedFile.ContentLength + 1];
                        //postedFile.InputStream.Read(content, 0, postedFile.ContentLength);
                        //inValue.FileData = new MemoryStream(content);
                        inValue.FileData = postedFile.InputStream;
                        client.UploadFile(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return(FileMessage.UnknowError);
                    }

                    return(FileMessage.Success);
                }
                catch
                {
                    return(FileMessage.UnknowError);
                }
            }
            else
            {
                return(f);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="postedFile">上传的文件对象</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <param name="userId">用户编号</param>
        /// <returns></returns>
        public static FileMessage UploadFile(HttpPostedFileBase postedFile, string key, out FileInfor fileInfor, int userId)
        {

            string useridstr = userId.ToString();

            if (useridstr.Length < 9)
            {
                for (int i = 0; i < (9 - useridstr.Length); i++)
                {
                    useridstr = "0" + useridstr;
                }
            }

            string[] folders = new string[2];
            folders[0] = useridstr.Substring(0, 3);
            folders[1] = useridstr.Substring(3, 3);

            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;

            fileInfor = new FileInfor();

            FileMessage f = client.GetFileNameByUser(key, postedFile.ContentLength, postedFile.FileName, null, out fileKey, out fileExt, folders);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName = fileKey;
                    fileInfor.FileSize = postedFile.ContentLength;

                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName = fileKey;
                    inValue.KeyName = key;
                    inValue.FileExt = fileExt;
                    inValue.SaveOrigin = true;

                    if (postedFile.InputStream.CanRead)
                    {
                        //byte[] content = new byte[postedFile.ContentLength + 1];
                        //postedFile.InputStream.Read(content, 0, postedFile.ContentLength);
                        //inValue.FileData = new MemoryStream(content);
                        inValue.FileData = postedFile.InputStream;
                        client.UploadFile(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return FileMessage.UnknowError;
                    }

                    return FileMessage.Success;
                }
                catch
                {
                    return FileMessage.UnknowError;
                }
            }
            else
            {
                return f;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="postedFile">上传的文件对象</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <returns></returns>
        public static FileMessage UploadFile(HttpPostedFileBase postedFile, string key, out FileInfor fileInfor)
        {
            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;
            fileInfor = new FileInfor();


            //TODO: 增加contenttype的读取。
            FileMessage f = client.GetFileName(key, postedFile.ContentLength, postedFile.FileName, out fileKey, out fileExt);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName = fileKey;
                    fileInfor.FileSize = postedFile.ContentLength;
                    fileInfor.FileExtName = fileExt;
                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName = fileKey;
                    inValue.KeyName = key;
                    inValue.FileExt = fileExt;
                    inValue.SaveOrigin = true;

                    if (postedFile.InputStream.CanRead)
                    {
                        //byte[] content = new byte[postedFile.ContentLength + 1];
                        //postedFile.InputStream.Read(content, 0, postedFile.ContentLength);
                        //inValue.FileData = new MemoryStream(content);
                        inValue.FileData = postedFile.InputStream;
                        client.UploadFile(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return FileMessage.UnknowError;
                    }

                    return FileMessage.Success;
                }
                catch
                {
                    return FileMessage.UnknowError;
                }
            }
            else
            {
                return f;
            }
        }