Fastdfs. Net client User Guide

Source: Internet
Author: User
Tags log4net

Although there is an example in the open-source fastdfs client with the configuration file of the client, a small meeting was held today, it is still necessary to write a User Guide to illustrate how to use this client.

In the open-source package, there are two project documents: fastdfs. Client and fastdfs. Web. The first one isSource codeFile, which is an example used by the DFS client. In fact, the use of the DFS client is very simple. For details, see the web file structure,CodeAnd the followingArticle:

Find the client or webProgramThe config folder in the set contains two configuration files, one of which is fastdfs. config, another log4net. config, followed by configuration logs. The client logs use the Apache open-source log4net component, fastdfs. the Config File configures the information used by the fastdfs client,

<Configuration> <networktimeout> 200000 </networktimeout> <! -- Connection timeout, can be configured according to the actual situation --> <charset> ISO8859-1 </charset> <! -- Transfer Encoding, which can be configured according to the actual situation. Generally, no need to configure --> <! -- Do not change the DFS server configuration without notice --> <trackerservers> <trackerserver address ="192.168.135.9"Port ="22122"Poolsize ="30"Groupname ="Test"/> </Trackerservers> <storageservers> <storageserver address ="192.168.135.9"Port ="23000"Poolsize ="70"/> </Storageservers> </configuration>

The entire configuration is so simple. The configuration items above will not be mentioned. The configuration items of trackerservers and storageservers are similar, but the configuration items of trackerserver have an additional groupname configuration item, the following details:

1. trackerservers and stroageservers can both be configured with multiple trackers and storage. You only need to add trackerserver and storageserver configuration items. One trackerserver and storageserver can only be configured with one tracker or storage, when multiple servers need to be configured, add the configuration items of trackerserver or storageserver;

2. address in the configuration items of trackerserver and storageserver indicates the IP address of the service, port indicates the port of the service listening, poolsize indicates the maximum number of connections in the client connection pool, and groupname in trackerserver indicates the group name of the current tracker item, storageserver does not need to be obtained because the storage is obtained through tracker on the server, so the storage does not need to configure groupname;

3. the size of poolsize is set according to the actual situation of your project. Generally, tracker is half the size of storage. This setting is because the tracker connection is very fast, and the storage connection needs to process file transmission, slow, so the affected connection pool needs to be larger;

The use of client code is actually very simple. First you need to apply the DLL of the client assembly, and then put fastdfs. config and log4net. copy the config file to your web config folder (or you can store the configuration in a unified directory), start the DFS client at the startup site, and then use it.

When starting the Web, add the following code to the global file:

  fastdfs   Private Static readonly ilog _ logger = logmanager. getlogger (methodbase. getcurrentmethod (). declaringtype); protected void application_start (Object sender, eventargs e) {try {xmlconfigurator. configure (New fileinfo (server. mappath (@"~ /Config/log4net. config "); fastdfsservice. Start (); If (null! = _ Logger) _ logger. Info ("application started! ");} Catch (exception exc) {If (null! = _ Logger) _ logger. Error (EXC. Message) ;}} protected void application_end (Object sender, eventargs e) {fastdfsservice. Stop (); If (null! = _ Logger) _ logger. Info ("Close the application! ") ;} 

In this way, the DFS client can be started. When you need to upload images, you can use the DFS client service to upload files and return the address of the image, so that the image is uploaded successfully, the Code is as follows:

 
FastdfsStringFilepath = fastdfsclient. Upload ("Test", Fileupload1.filebytes, tookextension. getextension (fileupload1.filename ));

To minimize the impact of DFS errors, we have studied the possibility of DFS client errors. The biggest possibility is that the connection pool is abnormal. Therefore, the restart function of the client thread pool has been developed, the client restart function is simple. You can add the following code to any location where you can trigger an event (we recommend that you open a separate page and set the user name and password for enhanced management:

 
FastdfsFastdfsservice. Reset ();

If you have any questions, please contact us!

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.