Coverage for girder/models/upload : 96%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # -*- coding: utf-8 -*-
############################################################################### # Copyright 2013 Kitware Inc. # # Licensed under the Apache License, Version 2.0 ( the "License" ); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ###############################################################################
""" This model stores temporary records for uploads that have been approved but are not yet complete, so that they can be uploaded in chunks of arbitrary size. The chunks must be uploaded in order. """
raise ValidationException('File size must not be negative.') raise ValidationException('Received bytes must not be larger than ' 'the total size of the upload.')
""" When a chunk is uploaded, this should be called to process the chunk. If this is the final chunk of the upload, this method will finalize the upload automatically. :param upload: The upload document to update. :type upload: dict :param chunk: The file object representing the chunk that was uploaded. :type chunk: file """
# If upload is finished, we finalize it
""" Requests the offset that should be used to resume uploading. This makes the request from the assetstore adapter. """
""" This should only be called manually in the case of creating an empty file, i.e. one that has no chunks. """
# Create a new item with the name of the file. name=upload['name'], creator={'_id': upload['userId']}, folder={'_id': upload['parentId']}) else: objectId=True, user={'_id': upload['userId']}, level=AccessType.WRITE)
item=item, name=upload['name'], size=upload['size'], creator={'_id': upload['userId']}, assetstore=assetstore, mimeType=upload['mimeType'])
# Add an async event for handlers that wish to process this file. 'file': file, 'assetstore': assetstore })
""" Creates a new upload record, and creates its temporary file that the chunks will be written into. Chunks should then be sent in order using the _id of the upload document generated by this method.
:param user: The user performing the upload. :type user: dict :param name: The name of the file being uploaded. :type name: str :param parentType: The type of the parent being uploaded into. :type parentType: str ('folder' or 'item') :param parent: The document representing the parent. :type parentId: dict :param size: Total size in bytes of the whole file. :type size: int :param mimeType: The mimeType of the file. :type mimeType: str :returns: The upload document that was created. """
'created': now, 'updated': now, 'userId': user['_id'], 'parentType': parentType.lower(), 'parentId': parent['_id'], 'assetstoreId': assetstore['_id'], 'size': size, 'name': name, 'mimeType': mimeType, 'received': 0 } |