示例#1
0
        /// <summary>
        /// 获取用于文件上传的参数
        /// </summary>
        /// <returns></returns>
        public ActionResult GetFileUploadParameter()
        {
            //注意,必须返回一个新的GUID用作文件ID
            FileUploadParameter parameter = new FileUploadParameter();

            parameter.UserId      = UserContext.User.Id;
            parameter.DomainId    = UserContext.User.Domain;
            parameter.FileService = _fileService;
            return(RespondDataResult(parameter));
        }
示例#2
0
        /// <summary>
        /// 上传普通文件
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public FileUploadResult UploadFile(FileUploadParameter param)
        {
            var result = new FileUploadResult();

            try
            {
                string fileName = MultipartUpload(param);
                result.FilePath = fileName;
            }
            catch (Exception ex)
            {
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
示例#3
0
        /// <summary>
        /// 上传普通文件
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public FileUploadResult UploadFile(FileUploadParameter param)
        {
            var result = new FileUploadResult();

            try
            {
                //return FastDFSClient.UploadFile(Node, content, ext);
                string fileName = MultipartUpload(param);
                result.FullFilePath = fileName;
            }
            catch (Exception ex)
            {
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
示例#4
0
    // This behavior is common for every page. It sets the way targetFolder is calculated, using FolderName.
    // Every class inheriting this base class will know where it stores file will know it and override FolderName as below.
    // All you do is to update existing classes (don't forget inheritance and virtual/override keywords).
    public ActionResult Save(IEnumerable <HttpPostedFileBase> uploadbox1, IEnumerable <HttpPostedFileBase> Negotiatedtarrifuploadbox1, FileUploadParameter uploadParam)
    {
        var uploadbox = (uploadbox1 != null) ? uploadbox1 : Negotiatedtarrifuploadbox1;

        if (uploadbox != null)
        {
            // Note FolderName property is used instead of parameter in original question.
            string targetFolder = new FileManagement().PathSave(FileType.documents) + "\\" + FolderName;
            // Missing code using targetFolder path
        }
    }
示例#5
0
        static void Main(string[] args)
        {
            //
            var config = FastDfsManager.GetConfigSection();
            //测试第二种方式
            //TrackerSection trackersSection = ConfigurationManager.GetSection("TrackerSection") as TrackerSection;
            //测试第三种方式
            //MyFastDFSClient.Test();

            StorageNode storageNode = null;

            var fileName = "";

            if (!File.Exists("test.jpg"))
            {
                return;
            }
            FileStream streamUpload = new FileStream(@"test.jpg", FileMode.Open);

            Console.WriteLine("进行上传图片/文件 测试");
            IUpload uploadFile = UploadFactory.Instance;
            //1 测试上传文件(非图片)——可行
            var fileUploadPara = new FileUploadParameter()
            {
                FileName = "test.jpg",
                //Content= File.ReadAllBytes("test.jpg"),
                Stream = streamUpload
            };
            //uploadFile.UploadFile(fileUploadPara);
            //2 测试上传图片
            //**注意,maxSize以后改为读取配置文件
            var fileUploadImage = new ImageUploadParameter(streamUpload, "test.jpg", null, 2 * 1024 * 1024)
            {
            };
            //FilePath:http://192.168.0.113/group1/M00/00/00/wKgAcVjHVVKAGNhPAAInn_BrY3k026.jpg
            var result = uploadFile.UploadImage(fileUploadImage);

            Console.WriteLine("上传成功,上传图片为{0}", result.FullFilePath);
            Console.WriteLine("*******************************");
            Console.WriteLine("1.直接获取刚才上传的文件的名称");
            Console.WriteLine("2.手动收入文件名称");
            Console.Write("请输入命令:");
            var    index            = Console.ReadLine();
            string filename_console = null;

            switch (index)
            {
            case "1":
                filename_console = result.FileName;
                Console.WriteLine("刚才上传的文件名为:{0}", filename_console);
                break;

            case "2":
                Console.WriteLine("请输入命令:");
                Console.WriteLine("请输入文件路径准备下载指定文件");
                filename_console = Console.ReadLine();
                break;

            default:
                Console.WriteLine("输入有误!");
                return;
            }

            IDownload downloadFile = DownloadFactory.Instance;

            Console.WriteLine("*******************************");
            var result_download = downloadFile.GetTargetFile(new FileDownParameter()
            {
                FileName = filename_console
            });

            Console.WriteLine("下载成功");
            Console.ReadLine();
            do
            {
                Console.WriteLine("\r\n1.Init");
                Console.WriteLine("2.GetStorageNode");
                Console.WriteLine("3.UploadFile");
                Console.WriteLine("4.RemoveFile");

                Console.Write("请输入命令:");
                var cmd = Console.ReadLine();

                switch (cmd)
                {
                case "1":
                    ConnectionManager.InitializeForConfigSection(config);
                    break;

                case "2":
                    storageNode = MyFastDFSClient.GetStorageNode(config.GroupName);
                    Console.WriteLine(storageNode.EndPoint);
                    break;

                case "3":
                    //暂时注释掉
                    fileName = MyFastDFSClient.UploadFile(storageNode, File.ReadAllBytes("test.jpg"), "jpg");


                    //此处不需要手动关闭了
                    //streamUpload.Close();
                    Console.WriteLine(fileName);
                    break;

                case "4":
                    MyFastDFSClient.RemoveFile(config.GroupName, fileName);
                    break;
                }
            } while (true);
        }