简体   繁体   English

如何从python Flask web app上传文件到Supabase Storage

[英]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.

相关问题 如何使用Python Flask将文件上传到Firebase存储? - How do you upload a file to Firebase Storage using Python Flask? Flask Upload如何配置文件存储路径 - Flask Upload How to configure file storage path Flask SocketIO web 应用程序拒绝接受来自 python 文件的连接 - Flask SocketIO web app refuses to accept connections from python file 使用 Python &#39;flask&#39; 应用程序登录并上传文件 - Login and upload file using Python 'flask' app 从 html 中的 python 文件中获取信息 [使用烧瓶的 web 应用程序] - Get information from python file in html [web app using flask] 从flask python将matplotlib输出图上传到云存储 - upload matplotlib output plot to cloud storage from flask python 从 url 上传文件到 Flask Python 3 服务器 - Upload file to Flask Python 3 server from url 如何在没有 BlobStore 的情况下从 Flask 表单将视频文件直接上传到 Cloud Storage? - How to upload a video file directly to Cloud Storage from a Flask form without BlobStore? 如何通过在同一EC2中运行的python-flask网络应用将图像上传到EC2? - How to upload image to EC2 through a python-flask web app running in the same EC2? 如何使用 Python 将 HTML 文件上传到 Azure Web 应用程序? - How to upload HTML file to an Azure Web App using Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM