def upload(request): client_id = request.POST['client_id'] private_key = request.POST['private_key'] input_file = request.POST['file'] current_dir = os.path.dirname(os.path.realpath(__file__)) # Using the filename like this without cleaning it is very # insecure so please keep that in mind when writing your own # file handling. file_path = os.path.join(current_dir, input_file.filename) output_file = open(file_path, 'wb') input_file.file.seek(0) while 1: data = input_file.file.read(2 << 16) if not data: break output_file.write(data) output_file.close() signer = GroupDocsRequestSigner(private_key) apiClient = ApiClient(signer) api = StorageApi(apiClient) fs = FileStream.fromFile(file_path) response = api.Upload(client_id, input_file.filename, fs) fs.inputStream.close() os.remove(file_path) return render_to_response('__main__:viewer.pt', {'guid': response.result.guid}, request=request)
def sample25(request): clientId = request.POST.get('client_id') privateKey = request.POST.get('private_key') inputFile = request.POST.get('file') fileId = request.POST.get('fileId') url = request.POST.get('url') basePath = request.POST.get('server_type') fileGuId = "" # Checking clientId and privateKey if IsNotNull(clientId) == False or IsNotNull(privateKey) == False: return render_to_response( '__main__:templates/sample25.pt', {'error': 'You do not enter your User Id or Private Key'}) ####Create Signer, ApiClient and Storage Api objects #Create signer object signer = GroupDocsRequestSigner(privateKey) #Create apiClient object apiClient = ApiClient(signer) #Create Storage Api object storage = StorageApi(apiClient) #Create AsyncApi object async = AsyncApi(apiClient) #Create MergeApi object merg = MergeApi(apiClient) #Create DocApi object doc = DocApi(apiClient) #Check is base path entered if basePath == "": #If base path empty set base path to the dev server basePath = 'https://api.groupdocs.com/v2.0' #Set base path for api storage.basePath = basePath async .basePath = basePath merg.basePath = basePath doc.basePath = basePath #If user choose local file upload if inputFile.filename != "": #A hack to get uploaded file size inputFile.file.seek(0, 2) fileSize = inputFile.file.tell() inputFile.file.seek(0) fs = FileStream.fromStream(inputFile.file, fileSize) ####Make a request to Storage API using clientId try: #Upload file to current user storage upload = storage.Upload(clientId, inputFile.filename, fs) if upload.status == "Ok": #Get file guid fileGuId = upload.result.guid except Exception, e: return render_to_response('__main__:templates/sample25.pt', {'error': str(e)})
except Exception, e: return render_to_response('__main__:templates/sample19.pt', { 'error' : str(e) }) if sourceFile != "" or targetFile != "": if sourceFile != "": try: #A hack to get uploaded file size sourceFile.file.seek(0, 2) fileSize = sourceFile.file.tell() sourceFile.file.seek(0) fs = FileStream.fromStream(sourceFile.file, fileSize) ####Make a request to Storage API using clientId #Upload file to current user storage response = api.Upload(clientId, sourceFile.filename, fs) sourceFileId = response.result.guid except Exception, e: return render_to_response('__main__:templates/sample19.pt', { 'error' : str(e) }) if targetFile != "": try: #A hack to get uploaded file size targetFile.file.seek(0, 2) fileSize = targetFile.file.tell() targetFile.file.seek(0) fs = FileStream.fromStream(targetFile.file, fileSize) ####Make a request to Storage API using clientId
except Exception, e: return render_to_response('__main__:templates/sample21.pt', {'error': str(e)}) if inputFile != "": try: #A hack to get uploaded file size inputFile.file.seek(0, 2) fileSize = inputFile.file.tell() inputFile.file.seek(0) fs = FileStream.fromStream(inputFile.file, fileSize) ####Make a request to Storage API using clientId #Upload file to current user storage response = storage.Upload(clientId, inputFile.filename, fs) guid = response.result.guid fileName = inputFile.filename fileId = "" except Exception, e: return render_to_response('__main__:templates/sample21.pt', {'error': str(e)}) if fileId != '': guid = fileId try: ####Make a request to Storage API using clientId #Obtaining all Entities from current user files = storage.ListEntities(userId=clientId, path='My Web Documents', pageIndex=0)