FastDFS使用说明

简介: 分布式文件存储服务器: 主要解决大批量的文件存储问题,由两部分组成 Tracker和 stroage
                    Tracker负责计算,Storage负责存储
                    所有的连接,都是连接Tracker,由Tracker负责计算应该使用哪一个Storage进行存储,再返回Storage地址进行使用
                    文件上传: 1.导包,2,添加多媒体解析器配置,3.Hander方法要有一个参数:MultipartFile类型
        

//镜像
    解压压缩包,点击Redis_02.vmx,进入虚拟机,修改配置为仅主机,开启虚拟机,点击我已移动该虚拟机
    账号  root   密码: itrcast  开机即可
    
//pom导入坐标

    (1)创建 Maven 工程 fastDFSdemo 
    由于 FastDFS 客户端 jar 包并没有在中央仓库中,所以需要使用下列命令手动安装 jar 包到 Maven 本地仓库(将 jar 包放到 d 盘 setup 目录)课程配套的本地仓库已经有此 jar 包,此步可省略。 
    mvn     install:install-file     -DgroupId=org.csource.fastdfs     -DartifactId=fastdfs          -Dversion=1.2 
    -Dpackaging=jar -Dfile=d:\setup\fastdfs_client_v1.20.jar 
    

    <commons-fileupload.version>1.3.1</commons-fileupload.version>

        <dependency>
            <groupId>org.csource.fastdfs</groupId>
            <artifactId>fastdfs</artifactId>
             <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
        </dependency>
        
//


6.2.2 配置文件 
(1)将“资源/fastDFS/配置文件”文件夹中的 fdfs_client.conf 拷贝到 pinyougou-shop-web 工程 config 文件夹 
(2)在 pinyougou-shop-web 工程 application.properties 添加配置 
                FILE_SERVER_URL=http://192.168.25.133/ 
(3)在 pinyougou-shop-web 工程 springmvc.xml 添加配置: 
<!-- 配置多媒体解析器 --> 
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">           <property name="defaultEncoding" value="UTF-8"></property> 
          <!-- 设定文件上传的最大值5MB,5*1024*1024 --> 
          <property name="maxUploadSize" value="5242880"></property> 
</bean>     

//后端Controller层    
导入文件工具类: FastDFSClient.java
Controller层    :UploadController.java

//前端Contoller层添加  uploadService
app.controller('goodsController' ,function($scope,$controller   ,goodsService,uploadService){    


//上传图片
    $scope.uploadFile=function(){
        uploadService.uploadFile().success(
            function(response){
                if(response.success){
                    $scope.image_entity.url= response.message;
                }else{
                    alert(response.message);                    
                }
            }        
        );
        
        
    }

<!-- 上传窗口 -->
<div class="modal fade" id="uploadModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" >
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">上传商品图片</h3>
        </div>
        <div class="modal-body">                            
            
            <table class="table table-bordered table-striped">
                  <tr>
                      <td>颜色</td>
                      <td><input  class="form-control" placeholder="颜色"  ng-model="image_entity.color" >  </td>
                  </tr>                
                  <tr>
                      <td>商品图片</td>
                      <td>
                        <table>
                            <tr>
                                <td>
                                <input type="file" id="file" />                                
                                    <button class="btn btn-primary" type="button"  ng-click="uploadFile()">
                                           上传
                                    </button>    
                                </td>
                                <td>
                                    <img  src="{{image_entity.url}}" width="200px" height="200px">
                                </td>
                            </tr>                        
                        </table>
                      </td>
                  </tr>                  
             </table>                
            
        </div>
        <div class="modal-footer">                        
            <button class="btn btn-success"  data-dismiss="modal" aria-hidden="true">保存</button>
            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
        </div>
      </div>
    </div>
</div>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值