試圖獲取用戶本地上傳的圖像的base64字符串。 我的html代碼是 -我想獲得圖像的base64字符串
<div class="col-md-4">
<label class="control-label"></label>
<input type="file" name="galleryImage" class="filestyle" data-buttonText="Select a Image">
<input class="btn btn-sm btn-info btn-block" name="getImageUrl" type="submit" Style="width: 100px;">
</div>
,在我的觀點
galleryImageURL = request.POST.get('galleryImage')
print(galleryImageURL)
galleryImage = requests.get(galleryImageURL).content
print(galleryImage)
base64EncodedImageString = imageBase64Encode(galleryImage)
print(base64EncodedImageString)
def imageBase64Encode(galleryImage):
with open(galleryImage, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
return encoded_string
我收到錯誤
Invalid URL '763814bc03a9838a7bae23ad4867ec01.jpg': No schema supplied. Perhaps you meant http://763814bc03a9838a7bae23ad4867ec01.jpg?
您需要獲取存儲該映像的臨時目錄,並根據該目錄創建完整路徑。我不記得怎麼把它從頭頂上掉下來,對不起,但那是問題所在。我認爲。 – Eamonn