簡體   English   中英

在pytesting中,如何提供文件/圖像的鏈接/指針以將圖像上傳到flask

[英]In pytesting, how to provide the link/pointer to the file/image for uploading the image in flask

我在python 3.5中使用flask,並嘗試使用pytest測試我的代碼以上傳圖像。我經歷了各種答案,但可惜無法解決我的問題。在github的鏈接中,它解釋了如何使用文件名,file_field https://gist.github.com/DazWorrall/1779861我也嘗試過這種方式,但是我的方向不正確。 請幫助我解決我的問題。 在這里,使用post方法上傳圖像,內容部分應該是多部分,但是關於數據,如何發送圖像數據及其路徑。

test_client.post(
    '/uploadimage',
    content_type='multipart/form-data',
    buffered=True,
    data=dict(
        file='user4.jpg', file_field=io.BytesIO(b"~/Downloads/images/")),
    follow_redirects=True)

在這里,運行pytest時無法識別該文件。 不知道為什么? 我希望能盡快得到答案。。謝謝。

res = test_client.post(products_url,content_type ='multipart / form-data',buffered = True,data = {'file':(io.BytesIO(b'〜/ Downloads / images'),'user4.jpg') ,})

一點點改變了數據的發送方式。 對我來說很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM