mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
13be84e4d4
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from flask import request
|
|
from flask_restful import marshal_with
|
|
|
|
import services
|
|
from controllers.web import api
|
|
from controllers.web.error import FileTooLargeError, NoFileUploadedError, TooManyFilesError, UnsupportedFileTypeError
|
|
from controllers.web.wraps import WebApiResource
|
|
from fields.file_fields import file_fields
|
|
from services.file_service import FileService
|
|
|
|
|
|
class FileApi(WebApiResource):
|
|
@marshal_with(file_fields)
|
|
def post(self, app_model, end_user):
|
|
# get file from request
|
|
file = request.files["file"]
|
|
|
|
# check file
|
|
if "file" not in request.files:
|
|
raise NoFileUploadedError()
|
|
|
|
if len(request.files) > 1:
|
|
raise TooManyFilesError()
|
|
try:
|
|
upload_file = FileService.upload_file(file, end_user)
|
|
except services.errors.file.FileTooLargeError as file_too_large_error:
|
|
raise FileTooLargeError(file_too_large_error.description)
|
|
except services.errors.file.UnsupportedFileTypeError:
|
|
raise UnsupportedFileTypeError()
|
|
|
|
return upload_file, 201
|
|
|
|
|
|
api.add_resource(FileApi, "/files/upload")
|