分布式文件系統fastdfs安裝以及python調用


參考:https://www.cnblogs.com/xiximayou/p/15722444.html

fastfds的安裝和使用

一、所需依賴

  • 操作系統:centos7.x(注意的是centos使用yum安裝相關依賴)
  • fastdfs:V6.06.tar.gz
  • libfastcommon:V1.0.43.tar.gz
  • fastdfs-nginx-module:fastdfs-nginx-module-1.22.tar.gz
  • nginx:nginx-1.18.0.tar.gz

切記:版本一定要對應好,不然會遇到很多難以名狀的問題。

二、fastdfs基礎知識

1、什么是fastdfs

(1)fastdfs是一個輕量級的開源分布式文件系統;

(2)fastdfs主要解決了大容量的文件存儲和高並發訪問的問題,文件存取時實現了負載均衡;

(3)fastdfs實現了軟件方式的RAID,可以使用廉價的IDE硬盤進行存儲支持存儲服務器在線擴容支持相同內容的文件只保存一份,節約磁盤空間;

(4)fastdfs只能通過Client API訪問,不支持POSIX訪問方式;

(5)fastdfs特別適合大中型網站使用,用來存儲資源文件(如:圖片、文檔、音頻、視頻等等)。

2、fastdfs框架圖

其中:

*Tracker Server:*跟蹤服務器,主要做調度工作,在訪問上起負載均衡的作用。記錄storage server的狀態,是連接Client和Storage server的樞紐。
*Storage Server:*存儲服務器,文件和meta data都保存到存儲服務器上。
*group:*組,也可稱為卷。同組內服務器上的文件是完全相同的文件標識:包括兩部分:組名和文件名(包含路徑)。
*meta data:*文件相關屬性,鍵值對(Key Value Pair)方式,如:width=1024,heigth=768。

3、上傳文件流程

(1)client詢問tracker上傳到的storage,不需要附加參數;
(2)tracker返回一台可用的storage;
(3)client直接和storage通訊完成文件上傳。

4、下載文件流程

(1)client詢問tracker下載文件的storage,參數為文件標識(組名和文件名);
(2)tracker返回一台可用的storage;
(3)client直接和storage通訊完成文件下載。

5、同步機制

(1)同一組內的storage server之間是對等的,文件上傳、刪除等操作可以在任意一台storage server上進行;
(2)文件同步只在同組內的storage server之間進行,采用push方式,即源服務器同步給目標服務器;
(3)源頭數據才需要同步,備份數據不需要再次同步,否則就構成環路了;
(4)上述第二條規則有個例外,就是新增加一台storage server時,由已有的一台storage server將已有的所有數據(包括源頭數據和備份數據)同步給該新增服務器。

6、tracker server目錄結構

--data

​ storage_groups.dat:存儲分組信息

​ storage_servers.dat:存儲服務器列表

--logs

​ trackerd.log:tracker server日志文件

7、storage_server目錄結構

--data

​ fdfs_storaged.pid:當前storage server的pid

​ storage_stat.dat:當前storage server統計信息

​ --sync:存放數據同步相關文件

​ binlog_index.dat:當前的binlog文件索引號

​ binlog.###:存放更新操作記錄(日志)

​ {ip_addr}_{ip_addr}_{port}.mark:存放同步的完成情況

--logs

​ storaged.log:storage server日志文件

以上理論參考:

ChinaUnix論壇:http://bbs.chinaunix.net/forum-240-1.html

github下載地址:https://github.com/happyfish100

腳本之家:https://www.jb51.net/article/197165.html

三、安裝

碰到權限問題,在指令前面加sudo。可以找一個地方建立一個文件夾,專門存放上述的壓縮包,然后操作時在同級目錄下解壓即可。

總體框架:

  • 一台服務器作為tracker,同時該服務器下有一個storage,該storage為group1
  • 還有一台服務器只作為storage,且有4個組,分別是group1-group4,每個組下面都有一個storage,其中group1的storage和tracker所在的服務器的storage同屬於一個組。

1、安裝libfastcommon

tar -zxvf V1.0.43.tar.gz
cd libfastcommon-1.0.43
./make.sh
sudo ./make.sh install

2、安裝fastfds

tar -zxvf V6.06.tar.gz
cd fastdfs-6.06
./make.sh
sudo ./make.sh install

對於包含tracker的服務器:注意這里可能存在權限問題,可以先切換到root用戶。

2.1、配置tracker

cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
vim tracker.conf
修改:base_path=/data02/file_server/tracker(必須手動先創建tracker目錄)
啟動tracker:/etc/init.d/fdfs_trackerd start
==========================================================
其它指令:
停止tracker:/etc/init.d/fdfs_trackerd stop
重啟tracker:/etc/init.d/fdfs_trackerd restart
查看tracker進程:ps aux | grep tracker

2.2、配置storage

cd /etc/fdfs/
cp storage.conf.sample storage.conf
修改:(storage目錄需要手動創建)
base_path=/data02/file_server/storage
store_path0=/data02/file_server/storage
tracker_server=192.168.0.101:22122(這里192.168.0.101是本機ip,22122和tracker.conf里面的port保持一致)
啟動:/etc/init.d/fdfs_storaged start
==========================================================
其它指令:
停止storage:/etc/init.d/fdfs_storaged stop
重啟storage:/etc/init.d/fdfs_storaged restart
查看storage進程:ps aux | grep storage

查看fastfds相應的配置信息:

fdfs_monitor /etc/fdfs/storage.conf

2.3、測試上傳

選擇192.168.0.101 tracker機器當做fdfs_client。

cd /etc/fdfs/
cp client.conf.sample client.conf
vim client.conf
修改:
base_path = /data02/file_server
tracker_server=192.168.0.101:22122
測試上傳文件:
fdfs_upload_file /etc/fdfs/client.conf net.png

3、安裝nginx以及fastdfs-nginx-module

3.1、未安裝nginx

假設之前我們並沒有安裝過nginx,我們可以這么操作:

tar -zxvf nginx-1.18.0.tar.gz
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
cd nginx-1.18.0
./configure --add-module=../fastdfs-nginx-module-1.22/src/
說明:以上這句指令是將fastdfs-nginx-module模塊加入的nginx配置中。如果提示缺少相關文件,可運行以下指令:
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel。--add-module的值是fastdfs-nginx-module的路徑。
sudo make
sudo make install

接下來,我們拷貝相關文件到指定目錄:

cd fastdfs-nginx-module-1.22/src
cp mod_fastdfs.conf /etc/fdfs/
cd /etc/fdfs/
vim mod_fastdfs.conf
修改:
tracker_server=192.168.0.101:22122(對應tracker.conf的ip地址以及port)
store_path0=/data02/file_server/storage(對應storage.conf里面的store_path0)
storage_server_port=23000
group_name=group1
group_count=1
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data02/file_server/storage

cd fastdfs-6.06/conf/
cp http.conf /etc/fdfs/
cp mime.types /etc/fdfs/
cd /etc/fdfs/
vim http.conf
修改:http.anti_steal.token_check_fail=/data02/file_server/fastdfs-6.06/conf/

接下來我們要修改nginx的相關配置:默認nginx配置在/use/local/nginx/conf/nginx.conf

vim /use/local/nginx/conf/nginx.conf
修改:
user root;
listen 8888;(這里的和storage.conf里面的http.server_port = 8888是一致的)
server_name  192.168.0.101;
並在該塊中添加:
location ~/group1/ {
    ngx_fastdfs_module;
}

保存后,接下來我們就可以測試nginx了。

檢查配置文件是否可用:sudo /usr/local/nginx/sbin/nginx -t
啟動nginx:sudo /usr/local/nginx/sbin/nginx
============================================
其它指令:
sudo /usr/local/nginx/sbin/nginx -s reload # 重啟nginx
sudo /usr/local/nginx/sbin/nginx -s stop # 立刻停止nginx
sudo /usr/local/nginx/sbin/nginx -s quit # nginx運行完后停止

補充:如果存在多個nginx的環境,我們可以指定nginx以及其配置文件的方式來啟動,比如:

/data02/file_server/nginx-1.18.0/objs/nginx -c /data02/file_server/nginx-1.18.0/conf/nginx.conf

當然你要確保nginx.conf也是修改過的。

3.2、已安裝過nginx

如果我們已經安裝過nginx,則進行如下操作:

ps aux | grep nginx(查看nginx的進程,並找到nginx的位置以及其配置文件,比如現在找到了nginx以及nginx.conf)
nginx -V(查看之前已經安裝的nginx的配置)
下載一個和該nginx相同版本的壓縮包並解壓,比如:nginx-1.18.0
cd nginx-1.18.0
./configure 剛才用-V得到的參數 --add-module=../fastdfs-nginx-module-1.22/src/
sudo make(這步之后不要用sudo make install指令)
然后會在objs/下生成編譯好的nginx文件。

接下來先停止之前運行的nginx:nginx -s stop
備份一下原始的nginx:cp nginx nginx.bak
然后將新編譯好的nginx復制進去:cp nginx-1.18.0/objs/nginx /usr/local/nginx/sbin/
接着修改nginx配置文件:vim /use/local/nginx/conf/nginx.conf
增加:
server {
        listen       8888;
        server_name  192.168.0.101;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        # 攔截包含 /group1/M00 請求,使用 fastdfs 這個 Nginx 模塊進行轉發
        location ~/group1/ {
            ngx_fastdfs_module;
        }    

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

}
最后啟動nginx:sudo /usr/local/nginx/sbin/nginx

3.3、補充

如果不想替換原本的nginx,那么我們可以修改自己下載的nginx文件,在nginx-1.18.0/conf/nginx.conf里面進行相應的修改,然后這樣啟動:sudo nginx-1.18.0/objs/nginx -c nginx-1.18.0/conf/nginx.conf。為了不和已有的nginx沖突,可能在./configure添加配置的時候指定相關文件的路徑,比如:

 ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=/data02/fastdfs/fastdfs-nginx-module/src 

如果在./configure時出現缺少相關依賴,可對照以下進行安裝:

錯誤./configure: error: the HTTP rewrite module requires the PCRE library.

解決:安裝pcre-devel:yum -y install pcre-devel

錯誤:./configure: error: the HTTP cache module requires md5 functions 

from OpenSSL library. You can either disable the module by using 
–without-http-cache option, or install the OpenSSL library into the system, 
or build the OpenSSL library statically from the source with nginx by using 
–with-http_ssl_module –with-openssl= options.

解決:yum -y install openssl openssl-devel

錯誤:./configure: error: the HTTP XSLT module requires the libxml2/libxslt    缺少libxml2

解決:yum -y install libxml2 libxml2-devel && yum -y install libxslt-devel

錯誤信息:./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.

解決方法:http_image_filter_module是nginx提供的集成圖片處理模塊,需要gd-devel的支持   yum -y install gd-devel

錯誤信息:./configure: error: perl module ExtUtils::Embed is required 缺少ExtUtils

解決方法:yum -y install perl-devel perl-ExtUtils-Embed

錯誤信息:./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library. 缺少GeoIP

解決方法:yum -y install GeoIP GeoIP-devel GeoIP-data

錯誤信息:./configure: error: the Google perftools module requires the Google perftools
library. You can either do not enable the module or install the library.

解決方法:yum -y install gperftools

最后測試上傳文件后在:http:192.168.0.101:8888/group1/M00/00/00/wKgACWHCyqeAR1X_AAAFTB0Vk_Y126.jpg可以訪問到了。

4、在另一台服務器上搭建storage

該台服務器對應Ip:192.168.0.9。首先要明確的是除了安裝tracker,storage,nginx,fastdfs-nginx-module都是要重新走一遍的,只是配置的時候有所不同。

4.1、相關依賴

將之前的libfastcommon、fastdfs、nginx、fastdfs-nginx-module拷貝到該服務器上。

4.2、配置storage

首先安裝好libfastcommon以及fastdfs,參考之前的步驟就行。然后開始配置storage:

cd /etc/fdfs/
cp storage.conf.sample storage.conf
vim storage.conf
修改:(storage目錄需要手動創建)
group=group1
port=23000
base_path=/data/data02/file_server/opt/storage
store_path0=/data/data03/storage
tracker_server=192.168.0.101:22122(這里指定tracker)
http.server_port=8688
 # 接下來我們同樣增加加個storage配置文件 cp storage.conf.sample storage2.conf vim storage2.conf 修改:(storage目錄需要手動創建) group=group2 port=23002 base_path=/data/data05/storage store_path0=/data/data05/storage tracker_server=192.168.0.101:22122(這里指定tracker) http.server_port=8688 cp storage.conf.sample storage3.conf vim storage3.conf 修改:(storage目錄需要手動創建) group=group3 port=23003 base_path=/data/data06/storage store_path0=/data/data06/storage tracker_server=192.168.0.101:22122(這里指定tracker) http.server_port=8688 cp storage.conf.sample storage4.conf vim storage4.conf 修改:(storage目錄需要手動創建) group=group4 port=23004 base_path=/data/data09/storage store_path0=/data/data09/storage tracker_server=192.168.0.101:22122(這里指定tracker) http.server_port=8688 啟動時我們要分別啟動每一個storage:(配置完后暫時先不啟動,等后續其它的一起配置完畢) fdfs_storaged /etc/fdfs/storage.conf start fdfs_storaged /etc/fdfs/storage2.conf start fdfs_storaged /etc/fdfs/storage3.conf start fdfs_storaged /etc/fdfs/storage4.conf start ========================================================== 其它指令: 停止storage:fdfs_storaged /etc/fdfs/storage.conf stop 重啟storage:fdfs_storaged /etc/fdfs/storage.conf restart 查看storage進程:ps aux | grep storage 當我們看到有4個storage進程的時候證明配置成功了。 

4.3、配置nginx

./configure --add-module=../fastdfs-nginx-module-1.22/src/
sudo make (這里可繼續選擇安裝,我就不安裝了)

不安裝時使用該nginx-1.18.0下的配置。

cd fastdfs-nginx-module-1.22/src
cp mod_fastdfs.conf /etc/fdfs/
cd /etc/fdfs/
vim mod_fastdfs.conf
修改:
tracker_server=192.168.0.101:22122
storage_server_port=23000
group_name=group1/group2/group3/group4
store_path0=/data/data02/file_server/opt/storage
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/data03/storage

[group2]
group_name=group2
storage_server_port=23002
store_path_count=1
store_path0=/data/data05/storage

[group3]
group_name=group3
storage_server_port=23003
store_path_count=1
store_path0=/data/data06/storage

[group4]
group_name=group4
storage_server_port=23004
store_path_count=1
store_path0=/data/data09/storage

接下來:

cd fastdfs-6.06/conf/
cp http.conf /etc/fdfs/
cp mime.types /etc/fdfs/
cd /etc/fdfs/
vim http.conf
修改:http.anti_steal.token_check_fail=/data/data02/file_server/soft/fastdfs-6.06/conf/

然后修改nginx配置:

vim nginx-1.18.0/conf/nginx.conf
修改:
user  root;
worker_processes  1;
 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;  #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8688; server_name 192.168.0.9; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location ~/group2/ { ngx_fastdfs_module; } location ~/group3/ { ngx_fastdfs_module; } location ~/group4/ { ngx_fastdfs_module; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } 

5、啟動所有服務

(1)啟動t192.168.0.101服務器:tracker以及storage

sudo /etc/init.d/fdfs_trackerd start
sudo /etc/init.d/fdfs_storaged start

(2)啟動192.168.0.9服務器:storage

fdfs_storaged /etc/fdfs/storage.conf start
fdfs_storaged /etc/fdfs/storage2.conf start
fdfs_storaged /etc/fdfs/storage3.conf start
fdfs_storaged /etc/fdfs/storage4.conf start

然后使用fdfs_monitor /etc/fdfs/storage.conf查看,看到有如下結果表示成功:

tracker server is 192.168.0.101:22122 group count: 4 Group 1: group name = group1 Storage 1: id = 192.168.0.101 ip_addr = 192.168.0.101 ACTIVE Storage 2: id = 192.168.0.9 ip_addr = 192.168.0.9 ACTIVE Group 2: group name = group2 Storage 1: id = 192.168.0.9 ip_addr = 192.168.0.9 ACTIVE Group 3: group name = group3 Storage 1: id = 192.168.0.9 ip_addr = 192.168.0.9 ACTIVE Group 4: group name = group4 Storage 1: id = 192.168.0.9 ip_addr = 192.168.0.9 ACTIVE 

(3)啟動192.168.0.9服務器:nginx

sudo /data/data02/file_server/soft/nginx-1.18.0/objs/nginx -c /data/data02/file_server/soft/nginx-1.18.0/conf/nginx.conf

(4)啟動192.168.0.101服務器:nginx

sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

用ps aux | grep nginx可查看nginx進程,需要注意的是有兩個進程:

root 18429 0.0 0.0 28144 680 ? Ss 12月22 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf rhino 18430 0.0 0.0 28924 2392 ? S 12月22 0:00 nginx: worker proces 

如果只有一個master進程,則說明是有問題的,可以去日志查看原因:/usr/local/nginx/logs/error.log

四、python操作fastfds進行上傳和下載

首先需要安裝包:pip install py3Fdfs

然后找一個位置,新建配置文件:fastfdfs_client.conf,里面配置:

connect_timeout=30
network_timeout=60
tracker_server = 192.168.0.101:22122
# tracker服務器的端口 http.tracker_server_port = 8888 

然后在同級目錄下新建一個python文件:test_fastdfs.py

# 在522服務器上可操作: from fdfs_client.client import get_tracker_conf, Fdfs_client import base64 from PIL import Image from io import BytesIO def main(): tracker_conf = get_tracker_conf('fastfdfs_client.conf') client = Fdfs_client(tracker_conf) # 文件上傳,結果返回:{'Group name': b'group1', 'Remote file_id': b'group1/M00/00/00/wKgf3F5MAe2AV_23AAAADL_GVeU370.txt', 'Status': 'Upload successed.', 'Local file name': 'test.txt', 'Uploaded size': '12B', 'Storage IP': b'192.168.31.220'} # 上傳后需要記錄該文件在哪,以Remote file_id標識 # upload_by_filename函數根據文件名上傳 print(dir(client)) result = client.upload_by_filename('2579937-d92ba54f63a2d63e.png') print(result) # upload_by_buffer將二進制文件上傳,並添加后綴進行保存 s = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAACK1BMVEVHcEwYd/8Wd/8Wd/8Vd/8XeP8Af/8Wdv8Wd/8Wdv8Wd//e6/8bev+NvP+10/8vhf9io/8aef/d6//z+P8whv/v9f85i/9uqv+51f9Ekv9Tmv+61v/O4v9+s/9CkP82iv8kf/9Klf8zh/9xrP8de/+Lu//t9P/I3//Z6P/y9//R5P/2+f+exv/u9f8rg//e7P9sqf+31f9Hk/+MvP95sP8xhv86jP8shP/b6f/c6v+fx/8yh//v9v+UwP9Fkv8gff/q8//k7/81if9Ol/8ifv9QmP+Sv//0+P8ffP/D3P84iv+GuP8YeP8cev/W5/////84i/9Rmf/l7/+Ft/+qzf8ee/+Vwf/a6v/Q4//S5f/P4/9IlP/f7P+axP+uz//X5/+tz/+Pvf82if+Wwv/T5f+Juv9WnP/G3f9Smv+gx//g7P8pgv/U5v9pp//N4f8/j/8thP9mpv+11P9coP8qgv+AtP/r8/8efP9npv8qg/9jpP8uhf8ogf8gfP8Zef9rqf/8/f8bef9Xnf9bn/9wq/9Aj/9mpf9kpP/5+/8ngP+cxf+pzf94sP/1+f9+tP+ozP9HlP97sv/M4f/n8f/w9v/Y6P9zrf+rzv9doP/W5v/A2v++2f83iv/l8P/o8v/o8f+71/9ho/+pzP/U5f/+/v/q8v+Rv/80iP9Mlv9Ckf+Xwv+/2f/j7//4+/88jf+Atf+Huf93r//7/P+y0v+51v9anv9PmP9qqP9lpf9BPI6rAAAACnRSTlMAK9S8j5MGf/L8h4HvUAAAAsZJREFUWMOl1vdbUlEYwPFX07KDQAyhSLFkKBC4KkPBlWluc+fOvdt72N577733rj+vc+6FGHLPvXDuD9wHHj7f+57DwwUAfMQlxCeh2I5FmC9MXIwQi1+AmDwk0t6haxL1cbT5dZM3mkQ8JNB8VnF7R90Jqod4in9i0m5eKV9+jOYhiXJ9i3Ua+3qqB9r82g7s088n07xgQKd+PNrzFHt7f24yxQsFdLeKa23PbJ3p9ryWlHmFIC8QaCu7Rvbv+qXhvNWr3r3EhYyiyF5ogtOaBrJ+NfZrMt++yq1R74zsIwbIxGeIt3N+rdz7wrFEwEcKFGTp8SP27m7O51sy1II+QqBg3Q6NHpkr67XZmeIeIvhCtEFDZkDa7FZRPy/gwh4FCn1yER8eUF6+yJ29Vbv4gv0N3YcFlLJe7pyj2cS/oO2x0T2EeTsq+ez3uysREpk/LKCUFXa9H3MaB79/IU9rrPuONIh5CPHNz4s+Vc+UGk229eSFA3v2HhLzwYELvW0frIrZ8b/+wnFHhagPDphRydjwgGvWNMkXrnrmxH1QoA6hbsfoyNDUxK8/TqNJ89pzUoIPBJKX5iBksBp+/kYqxXSpccadI8VDwKeuQKTw9YdKUb0xzWlEkjwXqMhX8X7ZBDI4v2FfXqa4Is1zgYMyBe9T0vAMjlTst0i8vm8J5Wc1Uz5PVqH/KN0Dv/4umULl82SGO9I9+PZPKbvveUDum+ZT+hJDq3QP/v2/2/jI23nTWdV4tHkwiuuTgInfv3t4Feica78KReXJEg5z+9f/kBQEfz/onwLZv75xZVhBkucCRrL/7bdRaEGa5wIucgcdkZM7Qm20PvBlGrLgh23maH0gMNAS/fpDAu7tMfn/AXPW1pg8UP//xBiIygOrB1YPrB5YPbB6YPXA6oHVA6sHVg+sHlg9sHpg9cDqgdUDqwdWD6z+H8aOr+GHK13YAAAAAElFTkSuQmCC' data = s.split(',')[1] image_data = base64.b64decode(data) result = client.upload_by_buffer(image_data, 'jpg') print(result) # 文件下載,結果返回:{'Remote file_id': b'group1/M00/00/00/wKgf3F5MAe2AV_23AAAADL_GVeU370.txt', 'Content': 't.txt', 'Download size': '12B', 'Storage IP': b'192.168.31.220'} # 第一個參數是保存的文件名,第二個參數是之前上傳得到的標識 result = client.download_to_file('t.png', b'group1/M00/00/00/wKgAZWHAQjiAAm4PAAFEJ0JhBgk569.png') print(result) #文件刪除,結果返回:('Delete file successed.', b'group1/M00/00/00/wKgf3F5MAe2AV_23AAAADL_GVeU370.txt', b'192.168.31.220') result = client.delete_file(b'group1/M00/00/00/wKgf3F5MAe2AV_23AAAADL_GVeU370.txt') if __name__ == '__main__': main() 

具體函數可參考:https://pypi.org/project/py3Fdfs/2.1.0/

參考

https://www.cnblogs.com/zhangmingda/p/12622590.html

https://www.jb51.net/article/197165.htm

https://blog.csdn.net/zglwy/article/details/52783244


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM