How to upload a picture using Fastdfs

Source: Internet
Author: User
Tags file size file upload

After the integration of Fastdfs and nginx, how to upload pictures and how to access the uploaded pictures.
You have not yet integrated reference
A tutorial on the integration of Centos 7+fastdfs and Nginx

Before uploading, let's introduce the FASTDFS framework.

    Fastdfs includes Tracker server and Storage Server two services, Tracker server is responsible for receiving uploads, downloading requests, receiving requests after the internal dispatch is finally completed by the Storage Server file upload and download

Upload Process

    1. Fastdfs initiated the long pass request for the
    2.FastDFS Server Tracker server receives the request
    3.Tracker server query available Storage Server
    4. Return storage Information about the Server (that is, the portal)
    5. Upload the file to the Storage server 6.Storage server to receive the file and generate the file name 7 based on the return information
    . Save the uploaded file to the picture warehouse
    8. Returns the access path and file name

Returns the path information structure
group1 m00/00/00/wkighvjvgzeagkeyaabazsfxnps529.png

Group1 group name: That is, the file upload storage group name 
M00 storage configured virtual path if Storage_path0 is configured M00/00/00/ 
This two-level directory is automatically created by the
system Wkighvjvgzeagkeyaabazsfxnps529.png is generated by the source storage server IP address and file timestamp, file size, and random information.

The ability to upload files is now started

First you have to have fastdfs_client package  
    Fastdfs_client-1.25.jar
Create a profile fdfs.conf
    content is tracker_server address
    tracker_ server=192.168.134.133:22122

and start writing the upload code.

public void Upload () throws Exception {//Add jar package to project//create a Profile configuration Tracker server address 

        Load configuration file Clientglobal.init ("fdfs.conf"); 

        Create a tracker client object trackerclient trackerclient = new Trackerclient (); 

        Use Trackerclient to connect trackersever objects Trackerserver Trackerserver = Trackerclient.getconnection (); 

        Create a straged server object storageserver storageserver = null; 

        Create a storage client object storageclient storageclient = new Storageclient (Trackerserver, storageserver); Upload picture//parameter with Storageclient object (do not have Chinese)//parameter two for file extension name//parameter III for file extensions information string[] Upload_fi 

        Le = Storageclient.upload_file ("C:/users/msi/pictures/20170218090505.png", "PNG", NULL);
        Upload_file stores the access path for (String s:upload_file) {System.out.println (s); Run result group1 m00/00/00/wkighvjvgzeagkeyaabazsfxnps529.png 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.