コード例 #1
0
def sample04(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    
    file_id = request.POST.get('fileId')
    # Checking clientId, privateKey and file_Id
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False or IsNotNull(file_id) == False:
        return render_to_response('__main__:templates/sample04.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
    api = StorageApi(apiClient)

    ####Make a request to Storage API using clientId

    try:
        #Obtaining all Entities from current user
        files = api.ListEntities(userId = clientId, path = '', pageIndex = 0)
        #Selecting file names
        for item in files.result.files: #selecting file names
            #Obtaining file name for entered file Id
           if item.guid == file_id:
               fileName = item.name

        ####Make a request to Storage Api for dowloading file

        #Obtaining file stream of downloading file and definition of folder where to download file
        currentDir = os.path.dirname(os.path.realpath(__file__))
        
        newpath = currentDir + "/../tmp/"
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        #Downlaoding of file
        fs = api.GetFile(clientId, file_id);

        if fs:

            filePath = newpath + fileName
        
            with open(filePath, 'wb') as fp:
                shutil.copyfileobj(fs.inputStream, fp)
            
            message = '<font color="green">File was downloaded to the <font color="blue">' + filePath + '</font> folder</font> <br />';
        else:
			raise Exception('Wrong file ID!')
    except Exception, e:
        return render_to_response('__main__:templates/sample04.pt',
                                  { 'error' : str(e) })
コード例 #2
0
def signature_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
        envelopId = jsonPostData['SourceId']
        # Create signer object
        signer = GroupDocsRequestSigner(privateKey)
        # Create apiClient object
        apiClient = ApiClient(signer)
        # Create AsyncApi object
        signature = SignatureApi(apiClient)
        # Create Storage object
        api = StorageApi(apiClient)
        if envelopId != '':
            time.sleep(5)
            print envelopId
            document = signature.GetSignatureEnvelopeDocuments(
                clientId, envelopId)
            if document.status == "Ok":
                guid = document.result.documents[0].documentId
                name = document.result.documents[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, guid)

                if fs:

                    filePath = downloadFolder + name

                    with open(filePath, 'wb') as fp:
                        shutil.copyfileobj(fs.inputStream, fp)
コード例 #3
0
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)