def uploadNewFileVersion(self, localPath, tempFilePath, resourceId, sequenceId, description = 'UpdateNewVersion'): if os.path.exists(localPath): if localPath != tempFilePath: shutil.copyfile(unicode(localPath), tempFilePath) else: raise WaitingOtherResourceException size = os.path.getsize(localPath) name = Utils.getNameFromPath(localPath) modifiedAt = Utils.getModifyTime(localPath) presignResponse = self.autoRepeatQuery(self.getFangCloudHttpClient().uploadNewFileVersionPresign, [-resourceId, sequenceId, size, name, modifiedAt]) if presignResponse.get('success', False): uploadURL = presignResponse['upload_url'] response = self.autoRepeatQuery(self.getFangCloudHttpClient().uploadNewFileVersion, [uploadURL, localPath, tempFilePath, description]) else: response = presignResponse if response['success']: result = self.__formatUploadNewFileResponse(response) else: result = response return result
def startMultiUploadNewFileVersion(self, localPath, fileId, sequenceId, sha1): """ \xe8\xaf\xb4\xe6\x98\x8e: \xe5\x8f\x91\xe9\x80\x81\xe5\xbc\x80\xe5\xa7\x8b\xe5\x88\x86\xe5\x9d\x97\xe4\xb8\x8a\xe4\xbc\xa0\xe8\xaf\xb7\xe6\xb1\x82-\xe9\x92\x88\xe5\xaf\xb9\xe6\x96\x87\xe4\xbb\xb6\xe6\x96\xb0\xe7\x89\x88\xe6\x9c\xac @param localPath: @param fileId: @param sequenceId: @param sha1: @return: """ try: startPostBody = {'sha1': sha1, 'file_size': str(os.path.getsize(localPath)), 'file_name': os.path.basename(localPath), 'sequence_id': sequenceId, 'remark': '', 'folder_id': '', 'modified_at': Utils.getModifyTime(localPath)} print startPostBody url = FangCloudUrl.URL['FILE_MULTI_UPLOAD_WITH_FILE_ID'] % fileId response = self.post(url, jsonData=startPostBody, logData=True) self.callbackHandler.handleHttpResponse(response) return response except UnAuthorizedException as exception: self.logger.error(exception, exc_info=1) return self.__refreshTokenWhenUnAuthorized() except ConnectionError: return HttpResponseResult.Failed
def uploadNewFilePresign(self, parentFolderId, localPath, description = None): try: postBody = {'folder_id': parentFolderId, 'file_name': Utils.getNameFromPath(localPath), 'file_size': str(os.path.getsize(localPath)), 'modified_at': Utils.getModifyTime(localPath)} if description is not None: postBody['description'] = description response = self.post(FangCloudUrl.URL['FILE_PRESIGN_UPLOAD'], jsonData=postBody, logData=True) self.callbackHandler.handleHttpResponse(response) return response except UnAuthorizedException as exception: self.logger.error(exception, exc_info=1) return self.__refreshTokenWhenUnAuthorized() except ConnectionError: return HttpResponseResult.Failed
def checkFileExistsOnServerAtTheSameDirWithTheSameName(self, localPath, parentFolderId, sha1, description = None): try: _, filename = os.path.split(localPath) urlQuery = {'folder_id': parentFolderId, 'file_name': filename, 'unencrypted_sha1': sha1, 'modified_at': Utils.getModifyTime(localPath)} if description is not None: urlQuery['description'] = description response = self.post(FangCloudUrl.URL['FILE_UPLOAD_CHECK_FILE_EXISTS_IN_SAME_DIR_IN_SAME_NAME'], None, urlQuery) self.callbackHandler.handleHttpResponse(response) return response except UnAuthorizedException as exception: self.logger.error(exception, exc_info=1) return self.__refreshTokenWhenUnAuthorized() except ConnectionError: return HttpResponseResult.Failed