check-req
This commit is contained in:
parent
fb6673c3cd
commit
e280709697
|
@ -58,19 +58,22 @@ def upload_storj(filecontent, filename, bucket_name):
|
||||||
|
|
||||||
@app.route('/api/upload', methods=['post'])
|
@app.route('/api/upload', methods=['post'])
|
||||||
def upload():
|
def upload():
|
||||||
print('upload serverless route is fine')
|
# check if the post request has the file part
|
||||||
print(request.path)
|
if 'file' not in request.files:
|
||||||
print(request.form)
|
return json({'error': 'No file part'}, status=400)
|
||||||
print(request.files)
|
file = request.files.get('file')
|
||||||
img = request.files['userpic']
|
# if user does not select file, browser also
|
||||||
if img:
|
# submit a empty part without filename
|
||||||
# Perform the file upload
|
if file.name == '':
|
||||||
filename = secure_filename(img.filename)
|
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
|
# Save the file to a temporary location
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
temp_path = os.path.join(temp_dir, filename)
|
temp_path = os.path.join(temp_dir, filename)
|
||||||
img.save(temp_path)
|
file.save(temp_path)
|
||||||
# Open the file in binary mode
|
# Open the file in binary mode
|
||||||
with open(temp_path, 'rb') as filecontent:
|
with open(temp_path, 'rb') as filecontent:
|
||||||
return jsonify(upload_storj(filecontent, filename, 'discoursio'))
|
result = upload_storj(filecontent, filename, 'discoursio')
|
||||||
return
|
return json({'message': 'File uploaded'}, status=200)
|
||||||
|
|
|
@ -36,13 +36,13 @@ export const ProfileSettingsPage = (props: PageProps) => {
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.onloadend = () => {
|
reader.onloadend = () => {
|
||||||
f.fileData = reader.result
|
f.fileData = reader.result
|
||||||
const data = new FormData()
|
const body = new FormData()
|
||||||
data.append('file', f)
|
body.append('file', f)
|
||||||
fetch('/api/upload', {
|
fetch('/api/upload', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: data
|
body
|
||||||
}).then((resp) => {
|
}).then((resp) => {
|
||||||
resp.json().then((url) => updateFormField('userpic', url))
|
resp.json().then((url) => updateFormField('file', url))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
reader.readAsDataURL(f)
|
reader.readAsDataURL(f)
|
||||||
|
@ -81,8 +81,7 @@ export const ProfileSettingsPage = (props: PageProps) => {
|
||||||
<input
|
<input
|
||||||
ref={userpicFile}
|
ref={userpicFile}
|
||||||
type="file"
|
type="file"
|
||||||
name="userpic"
|
name="file"
|
||||||
value="userpic"
|
|
||||||
hidden
|
hidden
|
||||||
onChange={handleUserpicUpload}
|
onChange={handleUserpicUpload}
|
||||||
/>
|
/>
|
||||||
|
|
15
vercel.json
15
vercel.json
|
@ -1,12 +1,9 @@
|
||||||
{
|
{
|
||||||
"functions": {
|
"routes": [
|
||||||
"api/upload.py": {
|
{
|
||||||
"memory": 3008,
|
"src": "/api/upload",
|
||||||
"maxDuration": 30
|
"headers": { "Content-Type": "application/json" },
|
||||||
},
|
"dest": "api/upload.py"
|
||||||
"api/feedback.js": {
|
|
||||||
"memory": 3008,
|
|
||||||
"maxDuration": 30
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user