我希望能够将文件从 Flask 上传到 Supabase Storage,但它只有 javascript api链接的文档 docs。
另外,我找不到任何示例或任何开源项目来做到这一点。这是我的上传功能:
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
Run Code Online (Sandbox Code Playgroud) 我使用 Go 和 mux 作为后端,使用简单的 html 作为前端。在响应中设置cookie的代码(不完整):
import "github.com/gorilla/sessions" // this is where sessions come from
var store = sessions.NewCookieStore([]byte("secret"))
store.Options = &sessions.Options{
MaxAge: 3600 * 24,
HttpOnly: true,
Path: "/",
Secure: true,
}
session, _ := store.Get(request, "uid")
session.Values["uid"] = token
err = session.Save(request, writer)
if err != nil {
log.Fatalln(err)
return
}
Run Code Online (Sandbox Code Playgroud)
这就是我获取的方式:
fetch("http://localhost:8000/user/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: 'include',
body: JSON.stringify(user),
})
Run Code Online (Sandbox Code Playgroud)
我还在后端启用了 cors:
c := cors.New(cors.Options{
AllowedOrigins: []string{"http://127.0.0.1:3000"},
AllowCredentials: true,
})
Run Code Online (Sandbox Code Playgroud)
set-cookie …