[英]How to upload file from python Flask web app to Supabase Storage
I want to be able to upload a file from Flask to Supabase Storage, but it only has documentation for the javascript api link to docs .我希望能够将文件从 Flask 上传到 Supabase 存储,但它只有 javascript api 链接到文档的文档。
Also, I can't find any examples or any open source project that does that.此外,我找不到任何示例或任何开源项目。 Here it is my function to upload:这是我上传的function:
def upload_file(self):
if 'file' not in request.files:
flash('No file part')
return redirect('/')
file = request.files['file']
if file.filename == '':
flash('No selected file')
return redirect('/')
filename = secure_filename(file.filename)
# upload to supabase storage
return file.path
from storage3 import create_client
url = "https://<your_supabase_id>.supabase.co/storage/v1"
key = "<your api key>"
headers = {"apiKey": key, "Authorization": f"Bearer {key}"}
storage_client = create_client(url, headers, is_async=False)
def upload_file(self):
if 'file' not in request.files:
flash('No file part')
return redirect('/')
file = request.files['file']
if file.filename == '':
flash('No selected file')
return redirect('/')
filename = secure_filename(file.filename)
buckets = storage_client.list_buckets()
bucket = buckets[0]
return bucket.upload(filename, file)
I didn't find official docs for python upload.我没有找到 python 上传的官方文档。
Didn't test the code above so appreciate any feedback.没有测试上面的代码,所以感谢任何反馈。
I've based this on the github repo https://github.com/supabase-community/storage-py and the docs herehttps://supabase-community.github.io/storage-py/api/bucket.html我基于 github repo https://github.com/supabase-community/storage-py和这里的文档https://supabase-community.github.io/storage-py/api/bucket.87418864
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.