-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (28 loc) · 1.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from flask import Flask, request, render_template, redirect, url_for
from google.cloud import storage
import os
import google.auth
app = Flask(__name__)
# Configure the GCS bucket name
GCS_BUCKET_NAME = 'sales-data-us-uk-fr'
# Initialize the Google Cloud Storage client
storage_client = storage.Client()
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
return 'No file part'
file = request.files['file']
if file.filename == '':
return 'No selected file'
if file:
# Upload the file to GCS
bucket = storage_client.bucket(GCS_BUCKET_NAME)
blob = bucket.blob(file.filename)
blob.upload_from_file(file)
return f'File {file.filename} uploaded to {GCS_BUCKET_NAME}.'
return render_template('index.html')
if __name__ == '__main__':
# Ensure the environment variable for the GCS service account key is set
#os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'path/to/your/service-account-file.json'
app.run(debug=True)