One, jar package
Jar Package Download: https://pan.baidu.com/s/1nwkAHU5 Password: tlv6
Or
Download project, install to Maven local repository
Project Download: https://pan.baidu.com/s/1i6SIm3b Password: JKJT
Second, the tool class code
PackageCom.common.fastFDS;ImportOrg.csource.common.NameValuePair;ImportOrg.csource.fastdfs.ClientGlobal;Importorg.csource.fastdfs.StorageClient1;ImportOrg.csource.fastdfs.StorageServer;Importorg.csource.fastdfs.TrackerClient;ImportOrg.csource.fastdfs.TrackerServer; Public classfastdfsclient {PrivateTrackerclient trackerclient =NULL; PrivateTrackerserver Trackerserver =NULL; PrivateStorageserver Storageserver =NULL; PrivateStorageClient1 storageclient =NULL; PublicFastdfsclient (String conf)throwsException {if(Conf.contains ("Classpath:") ) {conf= Conf.replace ("Classpath:", This. GetClass (). GetResource ("/"). GetPath ()); } clientglobal.init (conf); Trackerclient=Newtrackerclient (); Trackerserver=trackerclient.getconnection (); Storageserver=NULL; Storageclient=NewStorageClient1 (Trackerserver, storageserver); } /*** Upload File Method * <p>Title:uploadFile</p> * <p>description: </p> *@paramFileName File Full path *@paramextname file extension, not including (.) *@parammetas File extension information *@return * @throwsException*/ PublicString UploadFile (String fileName, String extname, namevaluepair[] metas)throwsException {String result=Storageclient.upload_file1 (FileName, Extname, Metas); returnresult; } PublicString UploadFile (String fileName)throwsException {returnUploadFile (FileName,NULL,NULL); } PublicString UploadFile (String fileName, String extname)throwsException {returnUploadFile (FileName, Extname,NULL); } /*** Upload File Method * <p>Title:uploadFile</p> * <p>description: </p> *@paramcontents of the Filecontent file, byte array *@paramextname File extension *@parammetas File extension information *@return * @throwsException*/ PublicString UploadFile (byte[] filecontent, String extname, namevaluepair[] metas)throwsException {String result=Storageclient.upload_file1 (filecontent, Extname, Metas); returnresult; } PublicString UploadFile (byte[] filecontent)throwsException {returnUploadFile (Filecontent,NULL,NULL); } PublicString UploadFile (byte[] filecontent, String extname)throwsException {returnUploadFile (Filecontent, Extname,NULL); }}
Third, the test code
@Test public void testfastfdsclient () throws exception{ // 1. Create a profile client.conf (this file name is arbitrary) // Configuration file Contents: tracker_server=192.168.**.**:22122 (your own FASTDFS server ip+ port number) //
2. Creating an Fastdfsclient instance fastdfsclient fastdfsclient =
new< /span> fastdfsclient ("e:/workspaces/conf/client.conf" // 3. Perform a picture upload and return the picture path string string = Fastdfsclient.uploadfile ("c:/waiguoren.jpg"
Four
Can draw on: http://www.cnblogs.com/fangwu/p/8367293.html
Fastdfs Tool class implements file upload _02