1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-19 10:26:17 +00:00

batchUploadImage

This commit is contained in:
skywalker
2023-12-05 16:09:41 +08:00
parent 2ce0f90cb8
commit f047a67855
2 changed files with 28 additions and 21 deletions

View File

@@ -306,11 +306,14 @@ class SeadocUploadImage(APIView):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
file = request.FILES.get('file')
if not file:
file_list = request.FILES.getlist('file')
if not file_list or not isinstance(file_list, list):
error_msg = 'Image can not be found.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# max 10 images
file_list = file_list[:10]
for file in file_list:
file_type, ext = get_file_type_and_ext(file.name)
if file_type != IMAGE:
error_msg = file_type_error_msg(ext, PREVIEW_FILEEXT.get('Image'))
@@ -329,9 +332,12 @@ class SeadocUploadImage(APIView):
repo_id = uuid_map.repo_id
username = payload.get('username', '')
parent_path = gen_seadoc_image_parent_path(file_uuid, repo_id, username)
file_path = posixpath.join(parent_path, file.name)
upload_link = get_seadoc_asset_upload_link(repo_id, parent_path, username)
relative_path = []
for file in file_list:
file_path = posixpath.join(parent_path, file.name)
files = {
'file': file,
'file_name': file.name,
@@ -344,7 +350,8 @@ class SeadocUploadImage(APIView):
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
image_url = '/' + file.name
return Response({'relative_path': image_url})
relative_path.append(image_url)
return Response({'relative_path': relative_path})
class SeadocDownloadImage(APIView):

View File

@@ -147,7 +147,7 @@ def gen_seadoc_image_parent_path(file_uuid, repo_id, username):
def get_seadoc_asset_upload_link(repo_id, parent_path, username):
obj_id = json.dumps({'parent_dir': parent_path})
token = seafile_api.get_fileserver_access_token(
repo_id, obj_id, 'upload-link', username, use_onetime=True)
repo_id, obj_id, 'upload-link', username, use_onetime=False)
if not token:
return None
upload_link = gen_file_upload_url(token, 'upload-api')