Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tddd80-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Gullander
tddd80-server
Commits
c5c2834b
Commit
c5c2834b
authored
3 months ago
by
Henrik Alsteryd
Browse files
Options
Downloads
Patches
Plain Diff
Uppload_image
parent
462ec23a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.py
+31
-0
31 additions, 0 deletions
app.py
with
31 additions
and
0 deletions
app.py
+
31
−
0
View file @
c5c2834b
...
...
@@ -7,6 +7,8 @@ from flask_bcrypt import Bcrypt
import
os
from
dotenv
import
load_dotenv
import
datetime
from
werkzeug.utils
import
secure_filename
load_dotenv
()
...
...
@@ -36,6 +38,14 @@ db = SQLAlchemy()
db
.
init_app
(
app
)
bcrypt
=
Bcrypt
(
app
)
UPLOAD_FOLDER
=
os
.
path
.
join
(
'
static
'
,
'
uploads
'
)
ALLOWED_EXTENSIONS
=
{
'
png
'
,
'
jpg
'
,
'
jpeg
'
}
app
.
config
[
'
UPLOAD_FOLDER
'
]
=
UPLOAD_FOLDER
def
allowed_file
(
filename
):
return
'
.
'
in
filename
and
filename
.
rsplit
(
'
.
'
,
1
)[
1
].
lower
()
in
ALLOWED_EXTENSIONS
# Many-to-Many-tabell för att hantera followers (en följare följer en annan)
followers
=
db
.
Table
(
'
followers
'
,
...
...
@@ -483,6 +493,27 @@ def unlike_review():
return
jsonify
({
"
message
"
:
f
"
Review
{
review
.
id
}
unliked by
{
user
.
username
}
"
}),
200
@app.route
(
'
/upload_image
'
,
methods
=
[
'
POST
'
])
def
upload_image
():
if
'
image
'
not
in
request
.
files
:
return
jsonify
({
'
error
'
:
'
No image provided
'
}),
400
file
=
request
.
files
[
'
image
'
]
if
file
.
filename
==
''
:
return
jsonify
({
'
error
'
:
'
No selected file
'
}),
400
if
file
and
allowed_file
(
file
.
filename
):
filename
=
secure_filename
(
file
.
filename
)
filepath
=
os
.
path
.
join
(
app
.
config
[
'
UPLOAD_FOLDER
'
],
filename
)
file
.
save
(
filepath
)
image_url
=
request
.
host_url
.
rstrip
(
'
/
'
)
+
f
'
/static/uploads/
{
filename
}
'
return
jsonify
({
'
image_url
'
:
image_url
}),
200
return
jsonify
({
'
error
'
:
'
Invalid file type
'
}),
400
# Blocklist loader
@jwt.token_in_blocklist_loader
def
check_if_token_in_blocklist
(
jwt_header
,
jwt_payload
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment