1. 本地圖片刪除(文件也是一樣)
#圖片刪除
def remove_img(imgPath):
if os.path.exists(imgPath): #判斷圖片是否存在
os.remove(imgPath)
return {"status": 1, "msg": "刪除成功"}
else:
return {"status": 0, "msg": "文件不存在"}
2. 圖片下載
#圖片下載
def download_img(imgUrl):
logoImgUrlTemp = imgUrl.split("/")[-1] #獲取圖片名稱及後面的參數
logoImgName = logoImgUrlTemp.split("?")[0] #只取圖片名稱,不要後面參數
filename = etc.config.IMG_UPLOAD_PATH + logoImgName #存儲圖片路徑 + 圖片名
urllib.request.urlretrieve(imgUrl, filename)
return filename