def sample33(request): clientId = request.POST.get('client_id') privateKey = request.POST.get('private_key') firstUrl = request.POST.get('url1') secondUrl = request.POST.get('url2') thirdUrl = request.POST.get('url3') basePath = request.POST.get('server_type') message = "" iframe = "" # Checking clientId, privateKey and file_Id if IsNotNull(clientId) == False or IsNotNull(privateKey) == False: return render_to_response('__main__:templates/sample33.pt', {'error': 'You do not enter all parameters'}) ####Create Signer, ApiClient and Storage Api objects #Create signer object signer = GroupDocsRequestSigner(privateKey) #Create apiClient object apiClient = ApiClient(signer) #Create Storage Api object storageApi = StorageApi(apiClient) #Create Async api object asyncApi = AsyncApi(apiClient) #Set base Path if basePath == "": basePath = "https://api.groupdocs.com/v2.0" storageApi.basePath = basePath asyncApi.basePath = basePath #Create list of URL's urlList = [firstUrl, secondUrl, thirdUrl] #Create empty list for uploaded files GUID's guidList = [] for url in urlList: try: #Upload file upload = storageApi.UploadWeb(clientId, url) if upload.status == "Ok": #Add GUID of uploaded file to list guidList.append(upload.result.guid) else: raise Exception(upload.error_message) except Exception, e: return render_to_response('__main__:templates/sample33.pt', {'error': str(e)})
def sample33(request): clientId = request.POST.get('client_id') privateKey = request.POST.get('private_key') firstUrl = request.POST.get('url1') secondUrl = request.POST.get('url2') thirdUrl = request.POST.get('url3') basePath = request.POST.get('server_type') message = "" iframe = "" # Checking clientId, privateKey and file_Id if IsNotNull(clientId) == False or IsNotNull(privateKey) == False: return render_to_response('__main__:templates/sample33.pt', { 'error' : 'You do not enter all parameters' }) ####Create Signer, ApiClient and Storage Api objects #Create signer object signer = GroupDocsRequestSigner(privateKey) #Create apiClient object apiClient = ApiClient(signer) #Create Storage Api object storageApi = StorageApi(apiClient) #Create Async api object asyncApi = AsyncApi(apiClient) #Set base Path if basePath == "": basePath = "https://api.groupdocs.com/v2.0" storageApi.basePath = basePath asyncApi.basePath = basePath #Create list of URL's urlList = [firstUrl, secondUrl, thirdUrl] #Create empty list for uploaded files GUID's guidList = [] for url in urlList: try: #Upload file upload = storageApi.UploadWeb(clientId, url) if upload.status == "Ok": #Add GUID of uploaded file to list guidList.append(upload.result.guid) else: raise Exception(upload.error_message) except Exception, e: return render_to_response('__main__:templates/sample33.pt', { 'error' : str(e) })
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)})
def sample43(request): clientId = request.POST.get('clientId') privateKey = request.POST.get('privateKey') fileId = request.POST.get('fileId') inputFile = request.POST.get('file') url = request.POST.get('url') basePath = request.POST.get('basePath') message = None iframe = None # Checking clientId and privateKey if not clientId or not privateKey: return render_to_response('__main__:templates/sample43.pt', dict(error='You do not enter all parameters')) ####Create Signer, ApiClient and Storage Api objects #Create signer object signer = GroupDocsRequestSigner(privateKey) #Create apiClient object apiClient = ApiClient(signer) #Create Doc Api object docApi = DocApi(apiClient) #Create Storage Api object storageApi = StorageApi(apiClient) #Create Async api object asyncApi = AsyncApi(apiClient) #Create Merge api object mergeApi = MergeApi(apiClient) #Set base Path if not basePath: basePath = "https://api.groupdocs.com/v2.0" docApi.basePath = basePath mergeApi.basePath = basePath asyncApi.basePath = basePath storageApi.basePath = basePath if url: try: # Upload file to current user storage using entered URl to the file upload = storageApi.UploadWeb(clientId, url) guid = upload.result.guid fileId = None except Exception, e: return render_to_response('__main__:templates/sample43.pt', dict(error=str(e)))
def compare_callback(request): currentDir = os.path.dirname(os.path.realpath(__file__)) if os.path.exists(currentDir + '/../user_info.txt'): f = open(currentDir + '/../user_info.txt') lines = f.readlines() f.close() clientId = lines[0].replace("\r\n", "") privateKey = lines[1] if IsNotNull(request.json_body): jsonPostData = request.json_body jobId = jsonPostData['SourceId'] # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create AsyncApi object async = AsyncApi(apiClient) # Create Storage object api = StorageApi(apiClient) if jobId != '': time.sleep(5) # Make request to api for get document info by job id jobs = async .GetJobDocuments(clientId, jobId) if jobs.status == 'Ok': # Get file guid resultGuid = jobs.result.outputs[0].guid name = jobs.result.outputs[0].name currentDir = os.path.dirname(os.path.realpath(__file__)) downloadFolder = currentDir + '/../downloads/' if not os.path.isdir(downloadFolder): os.makedirs(downloadFolder) #Downlaoding of file fs = api.GetFile(clientId, resultGuid) if fs: filePath = downloadFolder + name with open(filePath, 'wb') as fp: shutil.copyfileobj(fs.inputStream, fp)
except Exception, e: print e ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create StorageApi object storage = StorageApi(apiClient) # Create SignatureApi object signature = SignatureApi(apiClient) docApi = DocApi(apiClient) mergeApi = MergeApi(apiClient) asyncApi = AsyncApi(apiClient) if basePath == "": basePath = 'https://api.groupdocs.com/v2.0' #Set base path storage.basePath = basePath signature.basePath = basePath docApi.basePath = basePath mergeApi.basePath = basePath asyncApi.basePath = basePath guid = fileId #Create list with entered data enteredData = { "email": email, "country": country, "name": name, "street": street,
except Exception, e: return render_to_response('__main__:templates/sample19.pt', { 'error' : str(e) }) if source != '' or target != "": if source != "": sourceFileId = source if target != "": targetFileId = target # complare files try: info = compare.Compare(clientId, sourceFileId, targetFileId, callbackUrl) if info.status == "Ok": # Create AsyncApi object async = AsyncApi(apiClient) async.basePath = basePath # get job info try: counteer = 0 while counteer < 5: time.sleep(5) jobInfo = async.GetJobDocuments(clientId, info.result.job_id) # construct result if jobInfo.status == "Ok": if jobInfo.result.job_status == "Completed" or jobInfo.result.job_status == "Archived": # Generation of iframe URL using jobInfo.result.outputs[0].guid if basePath == "https://api.groupdocs.com/v2.0": iframe = 'https://apps.groupdocs.com/document-viewer/embed/' + jobInfo.result.outputs[0].guid elif basePath == "https://dev-api.groupdocs.com/v2.0": iframe = 'https://dev-apps.groupdocs.com/document-viewer/embed/' + jobInfo.result.outputs[0].guid
def sample42(request): clientId = request.POST.get("clientId") privateKey = request.POST.get("privateKey") fileId = request.POST.get("fileId") basePath = request.POST.get("basePath") iframe = None # Checking clientId, privateKey and fileId if not clientId or not privateKey or not fileId: return render_to_response("__main__:templates/sample42.pt", dict(error="You do not enter all parameters")) ####Create Signer, ApiClient and Storage Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create Ant Api object antApi = AntApi(apiClient) # Create Storage Api object storageApi = StorageApi(apiClient) # Create Async api object asyncApi = AsyncApi(apiClient) # Set base Path if not basePath: basePath = "https://api.groupdocs.com/v2.0" antApi.basePath = basePath asyncApi.basePath = basePath storageApi.basePath = basePath try: # Get all annotations from document getAllAnnotations = antApi.ListAnnotations(clientId, fileId) if getAllAnnotations.status == "Ok": # Create list of result document type convertType = ["pdf"] # Create JobInfo object and set attributes jobInfo = JobInfo() jobInfo.actions = "ImportAnnotations" jobInfo.out_formats = convertType jobInfo.status = "-1" jobInfo.email_results = True rand = random.randint(0, 500) jobInfo.name = "test" + str(rand) # Create job createJob = asyncApi.CreateJob(clientId, jobInfo) if createJob.status != "Ok": raise Exception(createJob.error_message) else: # Add document to the job addJobDocument = asyncApi.AddJobDocument(clientId, createJob.result.job_id, fileId, False) if addJobDocument.status != "Ok": raise Exception(addJobDocument.error_message) else: # Change job status jobInfo.status = "0" # Update job with new status updateJob = asyncApi.UpdateJob(clientId, createJob.result.job_id, jobInfo) if updateJob.status != "Ok": raise Exception(updateJob.error_message) time.sleep(5) # Get result file from job by it's ID getJobDocument = asyncApi.GetJobDocuments(clientId, createJob.result.job_id) if getJobDocument.status != "Ok": raise Exception(getJobDocument.error_message) else: # Get document GUID and Name from job fileGuid = getJobDocument.result.inputs[0].outputs[0].guid fileName = getJobDocument.result.inputs[0].outputs[0].name # Obtaining file stream of downloading file and definition of folder where to download file # Clear downloads folder currentDir = os.path.dirname(os.path.realpath(__file__)) if os.path.isdir(currentDir + "/../downloads"): # Get list of files for the_file in os.listdir(currentDir + "/../downloads"): file_path = os.path.join(currentDir + "/../downloads", the_file) try: # Delete file from folder os.unlink(file_path) except Exception, e: print e # Set path to were file will be downloaded newPath = currentDir + "/../downloads/" if not os.path.exists(newPath): os.makedirs(newPath) # Downlaoding of file fs = storageApi.GetFile(clientId, fileGuid) if fs: # Write file from stream to the downloads folder filePath = newPath + fileName with open(filePath, "wb") as fp: shutil.copyfileobj(fs.inputStream, fp) # Generate template message with link by clicking on which user can download file to he's local machine message = ( '<p><span style="color:green">File with annotations was downloaded to server\'s local folder. You can download it from <a href="/download_file?FileName=' + fileName + '">here</a></span></p>' ) # Generation of iframe URL using $pageImage->result->guid # iframe to production server if basePath == "https://api.groupdocs.com/v2.0": iframe = "https://apps.groupdocs.com/document-viewer/embed/" + fileGuid # iframe to dev server elif basePath == "https://dev-api.groupdocs.com/v2.0": iframe = "https://dev-apps.groupdocs.com/document-viewer/embed/" + fileGuid # iframe to test server elif basePath == "https://stage-api.groupdocs.com/v2.0": iframe = "https://stage-apps.groupdocs.com/document-viewer/embed/" + fileGuid elif basePath == "http://realtime-api.groupdocs.com": iframe = "http://realtime-apps.groupdocs.com/document-viewer/embed/" + fileGuid iframe = signer.signUrl(iframe) else: raise Exception("Wrong file ID!") else:
except Exception, e: print e ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create StorageApi object storage = StorageApi(apiClient) # Create SignatureApi object signature = SignatureApi(apiClient) docApi = DocApi(apiClient) mergeApi = MergeApi(apiClient) asyncApi = AsyncApi(apiClient) if not basePath: basePath = 'https://api.groupdocs.com/v2.0' #Set base path storage.basePath = basePath signature.basePath = basePath docApi.basePath = basePath mergeApi.basePath = basePath asyncApi.basePath = basePath guid = templateGuid #Create list with entered data enteredData = {"email": email, "country": country, "name": name, "street": street, "city": city} #Create new Datasource object dataSource = Datasource array = [] #Create DataSourceField object and filing it with entered data