Linux系统下curl命令上传文件,文件名包含逗号无法上传

使用curl命令,将备份好的图片全部重新导入到seaweedfs,图片全部以存储在seaweedfs中的fid命令,

fid中间有一个逗号,使用curl命令时报错:

curl: (26) couldn't open file "6"

curl命令:

curl -X PUT -F "fileUpload=@6,f6f7219fc0" "http://192.168.0.168:8180/6,f6f7219fc0"

其中,http://192.168.0.168:8180是seaweedfs启动的volume server.

解决办法:

使用双引号包含文件名,并开启转义;

curl -X PUT -F "fileUpload=@\"6,f6f7219fc0\"" "http://192.168.0.168:8180/6,f6f7219fc0"

 

导入脚本:

#!/bin/bash

if [ $# -ne 1 ];then
echo "[ Error ] Plead pass the image directory !"
exit 1
fi

ls -alt $1 | awk '{print $9}' | while read line
do
  if [[ $line != "." && $line != ".." ]];then
    if [ $( echo $line | grep "," | wc -l) -eq 1 ];then
      file_path="$1/$line"
      curl -X PUT -F "fileUpload=@\"${file_path}\"" "http://192.168.0.168:8180/${line}"
      echo $file_path
      echo "---------------------------------------------------------------"
    fi
  fi
done

 

图片存储路径: /home/weedfs/20171222

调用命令: sh upload.sh /home/weedfs/20171222

 

posted on 2017-12-23 17:27  天涯飞鸿  阅读(1332)  评论(0编辑  收藏  举报

导航