check-req

This commit is contained in:
tonyrewin 2023-01-28 02:07:25 +03:00
parent fb6673c3cd
commit e280709697
3 changed files with 25 additions and 26 deletions

View File

@ -58,19 +58,22 @@ def upload_storj(filecontent, filename, bucket_name):
@app.route('/api/upload', methods=['post'])
def upload():
print('upload serverless route is fine')
print(request.path)
print(request.form)
print(request.files)
img = request.files['userpic']
if img:
# Perform the file upload
filename = secure_filename(img.filename)
# check if the post request has the file part
if 'file' not in request.files:
return json({'error': 'No file part'}, status=400)
file = request.files.get('file')
# if user does not select file, browser also
# submit a empty part without filename
if file.name == '':
return json({'error': 'No selected file'}, status=400)
if file:
# save the file
filename = secure_filename(file.name)
# Save the file to a temporary location
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = os.path.join(temp_dir, filename)
img.save(temp_path)
file.save(temp_path)
# Open the file in binary mode
with open(temp_path, 'rb') as filecontent:
return jsonify(upload_storj(filecontent, filename, 'discoursio'))
return
result = upload_storj(filecontent, filename, 'discoursio')
return json({'message': 'File uploaded'}, status=200)

View File

@ -36,13 +36,13 @@ export const ProfileSettingsPage = (props: PageProps) => {
const reader = new FileReader()
reader.onloadend = () => {
f.fileData = reader.result
const data = new FormData()
data.append('file', f)
const body = new FormData()
body.append('file', f)
fetch('/api/upload', {
method: 'POST',
body: data
body
}).then((resp) => {
resp.json().then((url) => updateFormField('userpic', url))
resp.json().then((url) => updateFormField('file', url))
})
}
reader.readAsDataURL(f)
@ -81,8 +81,7 @@ export const ProfileSettingsPage = (props: PageProps) => {
<input
ref={userpicFile}
type="file"
name="userpic"
value="userpic"
name="file"
hidden
onChange={handleUserpicUpload}
/>

View File

@ -1,12 +1,9 @@
{
"functions": {
"api/upload.py": {
"memory": 3008,
"maxDuration": 30
},
"api/feedback.js": {
"memory": 3008,
"maxDuration": 30
"routes": [
{
"src": "/api/upload",
"headers": { "Content-Type": "application/json" },
"dest": "api/upload.py"
}
}
]
}