#NEWLINE# @ access . user #NEWLINE# @ describeRoute ( Description ( 'Upload a chunk of a file with multipart/form-data.' ) . consumes ( 'multipart/form-data' ) . param ( 'uploadId' , 'The ID of the upload record.' , paramType = 'form' ) . param ( 'offset' , 'Offset of the chunk in the file.' , dataType = 'integer' , paramType = 'form' ) . param ( 'chunk' , 'The actual bytes of the chunk. For external upload behaviors, this may be set to an opaque string that will be handled by the assetstore adapter.' , dataType = 'File' , paramType = 'body' ) . errorResponse ( 'ID was invalid.' ) . errorResponse ( 'Received too many bytes.' ) . errorResponse ( 'Chunk is smaller than the minimum size.' ) . errorResponse ( 'You are not the user who initiated the upload.' , 403 ) . errorResponse ( 'Failed to store upload.' , 500 ) ) #NEWLINE# def readChunk( self , params ) : #NEWLINE# #INDENT# '\n        After the temporary upload record has been created (see initUpload),\n        the bytes themselves should be passed up in ordered chunks. The user\n        must remain logged in when passing each chunk, to authenticate that\n        the writer of the chunk is the same as the person who initiated the\n        upload. The passed offset is a verification mechanism for ensuring the\n        server and client agree on the number of bytes sent/received.\n        ' #NEWLINE# self . requireParams ( ( 'offset' , 'uploadId' , 'chunk' ) , exc ) #NEWLINE# user = self . getCurrentUser ( ) #NEWLINE# upload = self . model ( 'upload' ) . load ( params [ 'uploadId' ] , exc = True ) #NEWLINE# offset = int ( params [ 'offset' ] ) #NEWLINE# chunk = params [ 'chunk' ] #NEWLINE# if ( upload [ 'userId' ] != user [ '_id' ] ) : #NEWLINE# #INDENT# raise AccessException ( 'You did not initiate this upload.' ) #NEWLINE# #UNINDENT# if ( upload [ 'received' ] != offset ) : #NEWLINE# #INDENT# raise RestException ( ( 'Server has received %s bytes, but client sent offset %s.' % ( upload [ 'received' ] , offset ) ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if isinstance ( chunk , cherrypy . _cpreqbody . Part ) : #NEWLINE# #INDENT# return self . model ( 'upload' ) . handleChunk ( upload , chunk . file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . model ( 'upload' ) . handleChunk ( upload , chunk ) #NEWLINE# #UNINDENT# #UNINDENT# except IOError as exc : #NEWLINE# #INDENT# if ( exc . errno == errno . EACCES ) : #NEWLINE# #INDENT# raise Exception ( 'Failed to store upload.' ) #NEWLINE# #UNINDENT# raise