Exemplo n.º 1
0
def sample14(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    path = request.POST.get('path')

    # Checking required parameters
    if IsNotNull(clientId) == False or IsNotNull(
            privateKey) == False or IsNotNull(path) == False:
        return render_to_response('__main__:templates/sample14.pt',
                                  {'error': 'You do not enter all parameters'})

    ### Create Signer, ApiClient, StorageApi and Document Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create StorageApi object
    storageApi = StorageApi(apiClient)
    # Create DocApi object
    docApi = DocApi(apiClient)

    # initialization some variables
    folderId = None
    users = ""

    # parse input path
    pathList = path.split('/')
    if len(path) > 1:
        last = pathList[-1]
        del pathList[-1]
        newPath = "/".join(pathList)
    else:
        last = pathList.pop(0)
        newPath = ""

    try:
        #### Get folder ID by path

        # Make a request to Storage API
        list = storageApi.ListEntities(clientId, newPath)
        if list.status == "Ok":
            for folder in list.result.folders:
                if (folder.name == last):
                    folderId = folder.id

        ### Get list of shares
        if folderId is not None:
            # Make a request to Document API
            shares = docApi.GetFolderSharers(clientId, int(folderId))
            if shares.status == "Ok" and len(shares.result.shared_users) > 0:
                for x in xrange(len(shares.result.shared_users)):
                    # construct users list
                    users += str(shares.result.shared_users[x].nickname)
                    if x != len(shares.result.shared_users) - 1:
                        users += ", "

    except Exception, e:
        return render_to_response('__main__:templates/sample14.pt',
                                  {'error': str(e)})
Exemplo n.º 2
0
def sample02(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')

    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response('__main__:templates/sample02.pt',
                                  { 'error' : 'You do not enter you 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
    api = StorageApi(apiClient)

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

        #Obtaining all Entities from current user
        files = api.ListEntities(userId = clientId, path = '', pageIndex = 0)
        #Obtaining file names
        names = ''
        for item in files.result.files:
        #selecting file names
           names += item.name + '<br>'

    except Exception, e:
        return render_to_response('__main__:templates/sample02.pt',
                                  { 'error' : str(e) })
Exemplo n.º 3
0
def sample17(request):

    clientId = request.POST.get("clientId")
    privateKey = request.POST.get("privateKey")
    inputFile = request.POST.get("file")
    url = request.POST.get("url")
    basePath = request.POST.get("basePath")
    resultId = None
    # Checking required parameters
    if not clientId or not privateKey:
        return render_to_response("__main__:templates/sample17.pt", dict(error="You do not enter all parameters"))

    ### Create Signer, ApiClient and StorageApi objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create StorageApi object
    api = StorageApi(apiClient)
    if not basePath:
        basePath = "https://api.groupdocs.com/v2.0"
    # Set base path
    api.basePath = basePath
    if url:
        try:
            # Upload file to current user storage using entered URl to the file
            upload = api.UploadWeb(clientId, url)
            resultId = upload.result.id
            inputFile = None
        except Exception, e:
            return render_to_response("__main__:templates/sample17.pt", dict(error=str(e)))
Exemplo n.º 4
0
def sample16(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('server_type')
    fileId = request.POST.get('fileId')
    guid = ""
    iframe = ""
    # Checking required parameters
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response('__main__:templates/sample16.pt',
                                  {'error': 'You do not enter all parameters'})

    ### Create Signer, ApiClient and Annotation Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create Storage object
    api = StorageApi(apiClient)
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    api.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = api.UploadWeb(clientId, url)
            guid = upload.result.guid
            fileId = ""
        except Exception, e:
            return render_to_response('__main__:templates/sample16.pt',
                                      {'error': str(e)})
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
def sample16(request):
    clientId = request.POST.get("client_id")
    privateKey = request.POST.get("private_key")
    inputFile = request.POST.get("file")
    url = request.POST.get("url")
    basePath = request.POST.get("server_type")
    fileId = request.POST.get("fileId")
    guid = ""
    iframe = ""
    # Checking required parameters
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response("__main__:templates/sample16.pt", {"error": "You do not enter all parameters"})

    ### Create Signer, ApiClient and Annotation Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create Storage object
    api = StorageApi(apiClient)
    if basePath == "":
        basePath = "https://api.groupdocs.com/v2.0"
        # Set base path
    api.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = api.UploadWeb(clientId, url)
            guid = upload.result.guid
            fileId = ""
        except Exception, e:
            return render_to_response("__main__:templates/sample16.pt", {"error": str(e)})
Exemplo n.º 7
0
def sample27(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    inputFile = request.POST.get('file')
    fileId = request.POST.get('fileId')
    url = request.POST.get('url')
    basePath = request.POST.get('basePath')
    name = request.POST.get('name')
    sex = request.POST.get('sex')
    age = request.POST.get('age')
    sunrise = request.POST.get('sunrise')
    type = request.POST.get('type')
    fileGuId = None
    # Checking clientId and privateKey
    if not clientId or not privateKey:
        return render_to_response('__main__:templates/sample27.pt',
                                  dict(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
    merge = MergeApi(apiClient)
    #Create DocApi object
    doc = DocApi(apiClient)
    #Check is base path entered
    if not 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
    merge.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, overrideMode=0)
            if upload.status == "Ok":
                #Get file guid
                fileGuId = upload.result.guid
        except Exception, e:
            return render_to_response('__main__:templates/sample27.pt',
                                      dict(error=str(e)))
Exemplo n.º 8
0
def sample16(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('basePath')
    fileId = request.POST.get('fileId')
    guid = None
    iframe = None
    # Checking required parameters
    if not clientId or not privateKey:
        return render_to_response('__main__:templates/sample16.pt',
                                  dict(error='You do not enter all parameters'))

    ### Create Signer, ApiClient and Annotation Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create Storage object
    api = StorageApi(apiClient)
    if not basePath:
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    api.basePath = basePath
    if url:
        try:
            # Upload file to current user storage using entered URl to the file
            upload = api.UploadWeb(clientId, url)
            guid = upload.result.guid
            fileId = None
        except Exception, e:
            return render_to_response('__main__:templates/sample16.pt',
                                      dict(error=str(e)))
Exemplo n.º 9
0
def sample35(request):
    ####Check which form is now field. If not "guid" that first form.
    if request.POST.get('guid') == None or request.POST.get('guid') == '':
        #Get posted data
        clientId = request.POST.get('clientId')
        privateKey = request.POST.get('privateKey')
        inputFile = request.POST.get('file')
        fileId = request.POST.get('guidField')
        url = request.POST.get('url')
        basePath = request.POST.get('basePath')
        # Checking clientId and privateKey
        if not clientId or not privateKey:
            return render_to_response('__main__:templates/sample35.pt',
                dict(error='You do not enter your User Id or Private Key', newForm=""))
        #Create signer object
        signer = GroupDocsRequestSigner(privateKey)
        #Create apiClient object
        apiClient = ApiClient(signer)
        #Create Storage Api object
        storage = StorageApi(apiClient)
        #Create DocApi object
        doc = DocApi(apiClient)
        #Check is base path entered
        if not 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
        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, overrideMode=0)
                if upload.status == "Ok":
                    #Get file guid
                    fileGuId = upload.result.guid
            except Exception, e:
                return render_to_response('__main__:templates/sample35.pt',
                    dict(error=str(e), newForm= ''))
        #If user choose upload file from web
        if url:
            try:
                # Upload file to current user storage using entered URl to the file
                uploadWeb = storage.UploadWeb(clientId, url)
                # Check if file uploaded successfully
                if uploadWeb.status == "Ok":
                    #Get file guid
                    fileGuId = uploadWeb.result.guid
            except Exception, e:
                return render_to_response('__main__:templates/sample35.pt',
                    dict(error=str(e), newForm= ''))
Exemplo n.º 10
0
def sample05(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('basePath')
    fileId = request.POST.get('srcPath')
    name = None
    message = None
    path = None
    destPath = request.POST.get('destPath')
    copy = request.POST.get('copy')
    move = request.POST.get('move')
    if destPath:
        if destPath.find("/") != -1:
            destPath = destPath
        elif destPath.find("\\") != -1 or destPath.find("/") == -1:
            destPath = destPath.replace("\\", "")
            destPath = destPath + "/"
    else:
        destPath = ''
    ####Check clientId, privateKey and file Id
    if not clientId or not privateKey:
        return render_to_response('__main__:templates/sample05.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)
    docApi = DocApi(apiClient)
    #Check base path
    if not basePath:
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    storageApi.basePath = basePath
    if url:

        try:
            # Upload file to current user storage using entered URl to the file
            upload = storageApi.UploadWeb(clientId, url)
            ID = upload.result.id
            ####Make a request to Storage API using clientId

            #Obtaining all Entities from current user
            files = storageApi.ListEntities(userId=clientId, path='My Web Documents', pageIndex=0)
            #Obtaining file name
            for item in files.result.files:
                #selecting file names
                if item.guid == upload.result.guid:
                    name = item.name
        except Exception, e:
            return render_to_response('__main__:templates/sample05.pt',
                                      {'error': str(e)})
Exemplo n.º 11
0
def sample05(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('server_type')
    fileId = request.POST.get('srcPath')
    ID = ""
    name = ''
    message = ''
    destPath = request.POST.get('destPath')
    copy = request.POST.get('copy')
    move = request.POST.get('move')

    ####Check clientId, privateKey and file Id
    if IsNotNull(clientId) == False or IsNotNull(
            privateKey) == False or IsNotNull(destPath) == False:
        return render_to_response('__main__:templates/sample05.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)
    #Check base path
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    api.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = api.UploadWeb(clientId, url)
            ID = upload.result.id

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

                #Obtaining all Entities from current user
                files = api.ListEntities(userId=clientId,
                                         path='My Web Documents',
                                         pageIndex=0)
                #Obtaining file name
                for item in files.result.files:
                    #selecting file names
                    if item.guid == upload.result.guid:
                        name = item.name

            except Exception, e:
                return render_to_response('__main__:templates/sample05.pt',
                                          {'error': str(e)})
        except Exception, e:
            return render_to_response('__main__:templates/sample05.pt',
                                      {'error': str(e)})
Exemplo n.º 12
0
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)})
Exemplo n.º 13
0
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) })
Exemplo n.º 14
0
def sample44(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    inputFile = request.POST.get('file')
    basePath = request.POST.get('basePath')
    firstName = request.POST.get('firstName')
    gender = request.POST.get('gender')
    lastName = request.POST.get('lastName')
    firstEmail = request.POST.get('firstEmail')
    secondEmail = request.POST.get('secondEmail')
    fileGuId = None
    # Checking clientId and privateKey
    if not clientId or not privateKey or not firstEmail or not firstName or not secondEmail:
        return render_to_response('__main__:templates/sample44.pt',
                                  dict(error='Please enter all required data', url1=''))
    ####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
    merge = MergeApi(apiClient)
    #Create DocApi object
    doc = DocApi(apiClient)
    #Create Signature object
    signature = SignatureApi(apiClient)
    #Check is base path entered
    if not 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
    merge.basePath = basePath
    doc.basePath = basePath
    signature.basePath = basePath
    #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, overrideMode=0)
        if upload.status == "Ok":
            #Get file guid
            fileGuId = upload.result.guid
    except Exception, e:
        return render_to_response('__main__:templates/sample44.pt',
                                  dict(error=str(e), url1=''))
Exemplo n.º 15
0
def sample03(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    folderPath = request.POST.get('folderPath')
    basePath = request.POST.get('basePath')
    guid = None
    name = None
    if folderPath:
        if folderPath.find("/") != -1:
            folderPath = folderPath
        elif folderPath.find("\\") != -1 or folderPath.find("/") == -1:
            folderPath = folderPath.replace("\\", "")
            folderPath = folderPath + "/"
    # Checking clientId and privateKey
    if not clientId or not privateKey:
        return render_to_response('__main__:templates/sample03.pt',
                                  dict(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
    api = StorageApi(apiClient)
    #Check base path
    if not basePath:
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    api.basePath = basePath
    if url:
        try:
            # Upload file to current user storage using entered URl to the file
            upload = api.UploadWeb(clientId, url)
            guid = upload.result.guid
            try:
                ####Make a request to Storage API using clientId

                #Obtaining all Entities from current user
                files = api.ListEntities(userId=clientId, path='My Web Documents', pageIndex=0)
                #Obtaining file name
                for item in files.result.files:
                    #selecting file names
                    if item.guid == guid:
                        name = item.name

            except Exception, e:
                return render_to_response('__main__:templates/sample03.pt',
                                          {'error': str(e)})

        except Exception, e:
            return render_to_response('__main__:templates/sample03.pt',
                                      {'error': str(e)})
Exemplo n.º 16
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) })
Exemplo n.º 17
0
def sample05(request):
    clientId = request.POST.get("client_id")
    privateKey = request.POST.get("private_key")
    inputFile = request.POST.get("file")
    url = request.POST.get("url")
    basePath = request.POST.get("server_type")
    fileId = request.POST.get("srcPath")
    ID = ""
    name = ""
    message = ""
    destPath = request.POST.get("destPath")
    copy = request.POST.get("copy")
    move = request.POST.get("move")

    ####Check clientId, privateKey and file Id
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False or IsNotNull(destPath) == False:
        return render_to_response("__main__:templates/sample05.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)
    # Check base path
    if basePath == "":
        basePath = "https://api.groupdocs.com/v2.0"
        # Set base path
    api.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = api.UploadWeb(clientId, url)
            ID = upload.result.id

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

                # Obtaining all Entities from current user
                files = api.ListEntities(userId=clientId, path="My Web Documents", pageIndex=0)
                # Obtaining file name
                for item in files.result.files:
                    # selecting file names
                    if item.guid == upload.result.guid:
                        name = item.name

            except Exception, e:
                return render_to_response("__main__:templates/sample05.pt", {"error": str(e)})
        except Exception, e:
            return render_to_response("__main__:templates/sample05.pt", {"error": str(e)})
Exemplo n.º 18
0
def sample03(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('server_type')
    guid = ""
    name = ""
    # Checking clientId and privateKey
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response('__main__:templates/sample03.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
    api = StorageApi(apiClient)
    #Check base path
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
    #Set base path
    api.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = api.UploadWeb(clientId, url)
            guid = upload.result.guid
            try:
                ####Make a request to Storage API using clientId

                #Obtaining all Entities from current user
                files = api.ListEntities(userId = clientId, path = 'My Web Documents', pageIndex = 0)
                #Obtaining file name
                for item in files.result.files:
                    #selecting file names
                    if item.guid == guid:
                        name = item.name

            except Exception, e:
                return render_to_response('__main__:templates/sample03.pt',
                    { 'error' : str(e) })

        except Exception, e:
            return render_to_response('__main__:templates/sample03.pt',
                { 'error' : str(e) })
Exemplo n.º 19
0
def sample24(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    url = request.POST.get('url')
    basePath = request.POST.get('basePath')
    iframe = None
    # Checking required parameters
    if not clientId or not privateKey or not url:
        return render_to_response('__main__:templates/sample24.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 Storage Api object
    storage = StorageApi(apiClient)
    if not basePath:
        basePath = 'https://api.groupdocs.com/v2.0'
    storage.basePath = basePath
    # Upload file to current user storage using entered URl to the file
    upload = storage.UploadWeb(clientId, url)
    # Check if file uploaded successfully
    if upload.status == "Ok":
        # Generation of Embedded Viewer URL with uploaded file GuId
    # Generation of iframe URL using pageImage.result.guid
        if basePath == "https://api.groupdocs.com/v2.0":
            iframe = 'https://apps.groupdocs.com/document-viewer/embed/' + upload.result.guid
        elif basePath == "https://dev-api.groupdocs.com/v2.0":
            iframe = 'https://dev-apps.groupdocs.com/document-viewer/embed/' + upload.result.guid
        elif basePath == "https://stage-api.groupdocs.com/v2.0":
            iframe = 'https://stage-apps.groupdocs.com/document-viewer/embed/' + upload.result.guid
        iframe = signer.signUrl(iframe)


    # If request was successful - set variables for template
    return render_to_response('__main__:templates/sample24.pt',
        {
            'userId' : clientId,
            'privateKey' : privateKey,
            'url' : url,
            'iframe' : iframe,
        },
        request=request)
Exemplo n.º 20
0
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)})
Exemplo n.º 21
0
def sample30(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    file_guid = ""
    message = ""
    file_name = request.POST.get('fileName')
    # Checking clientId, privateKey and file_Id
    if IsNotNull(clientId) == False or IsNotNull(
            privateKey) == False or IsNotNull(file_name) == False:
        return render_to_response('__main__:templates/sample30.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:
        #Get all files from account
        allFiles = api.ListEntities(clientId, "", extended=False)
        if allFiles.status == "Ok":
            for i in range(len(allFiles.result.files)):
                if allFiles.result.files[i].name == file_name:
                    file_guid = allFiles.result.files[i].guid
            try:
                if file_guid == "":
                    message = '<span style="color: red">This file is no longer available</span>'
                else:
                    #Delete file from GroupDocs account
                    delete = api.Delete(clientId, file_guid)
                    # Check delete dtatus.
                    if delete.status == "Ok":
                        #            If status Ok return successful message
                        message = '<span style="color: green">Done, file deleted from your GroupDocs Storage</span>'
                    else:
                        raise Exception(delete.error_message)
            except Exception, e:
                return render_to_response('__main__:templates/sample30.pt',
                                          {'error': str(e)})
        else:
Exemplo n.º 22
0
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) })
Exemplo n.º 23
0
def sample24(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    url = request.POST.get('url')
    basePath = request.POST.get('server_type')
    # Checking required parameters
    if IsNotNull(clientId) == False or IsNotNull(
            privateKey) == False or IsNotNull(url) == False:
        return render_to_response('__main__:templates/sample24.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
    storage = StorageApi(apiClient)
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
    storage.basePath = basePath
    # Upload file to current user storage using entere URl to the file
    upload = storage.UploadWeb(clientId, url)
    # Check if file uploaded successfully
    if upload.status == "Ok":
        # Generation of Embeded Viewer URL with uploaded file GuId
        # Generation of iframe URL using pageImage.result.guid
        if basePath == "https://api.groupdocs.com/v2.0":
            iframe = 'https://apps.groupdocs.com/document-viewer/embed/' + upload.result.guid
        elif basePath == "https://dev-api.groupdocs.com/v2.0":
            iframe = 'https://dev-apps.groupdocs.com/document-viewer/embed/' + upload.result.guid
        elif basePath == "https://stage-api.groupdocs.com/v2.0":
            iframe = 'https://stage-apps.groupdocs.com/document-viewer/embed/' + upload.result.guid
        iframe = signer.signUrl(iframe)

    # If request was successfull - set variables for template
    return render_to_response('__main__:templates/sample24.pt', {
        'userId': clientId,
        'privateKey': privateKey,
        'url': url,
        'iframe': iframe,
    },
                              request=request)
Exemplo n.º 24
0
def sample34(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    folder = request.POST.get('folder')
    basePath = request.POST.get('server_type')
    # Checking clientId, privateKey and folder
    if IsNotNull(clientId) == False or IsNotNull(
            privateKey) == False or IsNotNull(folder) == False:
        return render_to_response('__main__:templates/sample34.pt',
                                  {'error': 'You do not enter all parameters'})
    #Remove tags and spaces from entered data
    clientId = re.sub('<[^>]*>', '', clientId.strip())
    privateKey = re.sub('<[^>]*>', '', privateKey.strip())
    folder = re.sub('<[^>]*>', '', folder.strip())
    if basePath == "":
        basePath = "https://api.groupdocs.com/v2.0"
    basePath = re.sub('<[^>]*>', '', basePath)
    ####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)
    storageApi.basePath = basePath
    ####Make a request to Storage API using clientId

    try:
        #Check entered path for propper slashes
        if folder.find("\\") != -1:
            folder = folder.replace("\\", "/")
        #Create folder
        createFolder = storageApi.Create(clientId, folder)
        #Check status
        if createFolder.status == "Ok":
            #If status Ok generate message with successful result
            message = '<span style="color:green">Folder was created ' + folder + '</span>'
        else:
            raise Exception(createFolder.error_message)
    except Exception, e:
        return render_to_response('__main__:templates/sample34.pt',
                                  {'error': str(e)})
Exemplo n.º 25
0
def sample34(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    folder = request.POST.get('folder')
    basePath = request.POST.get('basePath')
    # Checking clientId, privateKey and folder
    if not clientId or not privateKey or not folder:
        return render_to_response('__main__:templates/sample34.pt',
                                  dict(error='You do not enter all parameters'))
        #Remove tags and spaces from entered data
    clientId = re.sub('<[^>]*>', '', clientId.strip())
    privateKey = re.sub('<[^>]*>', '', privateKey.strip())
    folder = re.sub('<[^>]*>', '', folder.strip())
    if not basePath:
        basePath = "https://api.groupdocs.com/v2.0"
    basePath = re.sub('<[^>]*>', '', basePath)
    ####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)
    storageApi.basePath = basePath
    ####Make a request to Storage API using clientId

    try:
        #Check entered path for slashes
        if folder.find("\\") != -1:
            folder = folder.replace("\\", "/")
            #Create folder
        createFolder = storageApi.Create(clientId, folder)
        #Check status
        if createFolder.status == "Ok":
            #If status Ok generate message with successful result
            message = '<span style="color:green">Folder was created ' + folder + '</span>'
        else:
            raise Exception(createFolder.error_message)
    except Exception, e:
        return render_to_response('__main__:templates/sample34.pt',
                                  {'error': str(e)})
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)
Exemplo n.º 27
0
def sample22(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('server_type')
    fileId = request.POST.get('fileId')
    guid = ""
    email = request.POST.get('email')
    name = request.POST.get('first_name')
    lastName = request.POST.get('last_name')

    # Checking required parameters
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False or IsNotNull(email) == False or IsNotNull(name) == False or IsNotNull(lastName) == False:
        return render_to_response('__main__:templates/sample22.pt',
            { 'error' : 'You do not enter all parameters' })

    ### Create Signer, ApiClient and Mgmt Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create mgmtApi object
    mgmt = MgmtApi(apiClient)
    # Create StorageApi object
    storage = StorageApi(apiClient)
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    storage.basePath = basePath
    # Declare which server to use
    mgmt.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = storage.UploadWeb(clientId, url)
            guid = upload.result.guid
            fileId = ""
        except Exception, e:
            return render_to_response('__main__:templates/sample16.pt',
                { '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)
Exemplo n.º 29
0
def sample08(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('server_type')
    fileId = request.POST.get('fileId')
    guid = ""
    pageNumber = request.POST.get('pageNumber') or 0
    #Checking parameters
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response('__main__:templates/sample08.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 DocApi object
    docApi = DocApi(apiClient)
    #Create Storage Api object
    api = StorageApi(apiClient)
    ####Make request to DocApi using user id
    #Check base path
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    docApi.basePath = basePath
    api.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = api.UploadWeb(clientId, url)
            guid = upload.result.guid
            fileId = ""
        except Exception, e:
            return render_to_response('__main__:templates/sample08.pt',
                { 'error' : str(e) })
Exemplo n.º 30
0
def sample07(request):
    clientId = request.POST.get("client_id")
    privateKey = request.POST.get("private_key")
    #Checking parameters
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response(
            '__main__:templates/sample07.pt',
            {'error': 'You do not enter you 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
    storageApi = StorageApi(apiClient)
    ####Make a request to Storage API using clientId

    try:
        #Obtaining all Entities from current user
        files = storageApi.ListEntities(clientId, "", extended=True)
    except Exception, e:
        return render_to_response('__main__:templates/sample07.pt',
                                  {'error': str(e)})
Exemplo n.º 31
0
            try:
                #Delete file from folder
                os.unlink(file_path)

            except Exception, e:
                print e
    ### Create Signer, ApiClient and AsyncApi objects

    # 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 basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    api.basePath = basePath
    async.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = api.UploadWeb(clientId, url)
            guid = upload.result.guid
            fileId = ""
        except Exception, e:
            return render_to_response('__main__:templates/sample16.pt',
                { 'error' : str(e) })
Exemplo n.º 32
0
def sample41(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('basePath')
    fileId = request.POST.get('fileId')
    callbackUrl = request.POST.get('callbackUrl')
    emailsArray = request.POST.getall('email[]')
    guid = None
    iframe = None
    # Checking required parameters
    if not clientId or not privateKey or not emailsArray:
        return render_to_response('__main__:templates/sample41.pt',
                                  dict(error='You do not enter all parameters'))
    #Get current work directory
    currentDir = os.path.dirname(os.path.realpath(__file__))
    #Create text file
    fp = open(currentDir + '/../user_info.txt', 'w')
    #Write user info to text file
    fp.write(clientId + "\r\n" + privateKey)
    fp.close()
    #Check if last list element is empty string
    if emailsArray[1] == '':
        #Remove empty element from list
        del emailsArray[1]
    ### 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)
    mgmtApi = MgmtApi(apiClient)
    antApi = AntApi(apiClient)
    if not basePath:
        basePath = "https://api.groupdocs.com/v2.0"
        #Set base path
    storage.basePath = basePath
    mgmtApi.basePath = basePath
    if url:
        try:
            # Upload file to current user storage using entered URl to the file
            upload = storage.UploadWeb(clientId, url)
            guid = upload.result.guid
            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)
                #Obtaining file name
                for item in files.result.files:
                    #selecting file names
                    if item.guid == guid:
                        fileName = item.name

            except Exception, e:
                return render_to_response('__main__:templates/sample41.pt',
                                          {'error': str(e)})
            fileId = None
        except Exception, e:
            return render_to_response('__main__:templates/sample41.pt',
                                      {'error': str(e)})
Exemplo n.º 33
0
def sample45(request):
    # Set variables and get POST data
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    folderName = request.POST.get('folderName')
    fileName = request.POST.get('fileName')
    basePath = request.POST.get('basePath')
    # Checking required parameters
    if not clientId or not privateKey or not fileName:
        return render_to_response('__main__:templates/sample45.pt',
                                  dict(error='You do not enter all parameters'))

    ### Create Signer, ApiClient, StorageApi and Document Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create DocApi object
    doc = DocApi(apiClient)
    #Create Storage object
    storage = StorageApi(apiClient)
    #Check base path
    if not basePath:
        basePath = 'https://api.groupdocs.com/v2.0'
    #Set base path
    doc.basePath = basePath
    storage.basePath = basePath
    try:
        #Check folder name
        if not folderName:
            folderName = ''
        #Get all files
        allFiles = storage.ListEntities(clientId, folderName)
        if allFiles.status == "Ok":
            #Fet file guid by it's name
            for item in allFiles.result.files:
                if item.name == fileName:
                    guid = item.guid
            #Get document info
            documentInfo = doc.GetDocumentMetadata(clientId, guid)
            if documentInfo.result is not None:
                #Generate table with statistic data
                result = "<table class='border'>"
                result += "<tr><td><font color='green'>Parameter</font></td><td><font color='green'>Info</font></td></tr>"
                for item in documentInfo.result.__dict__:
                    if item != 'swaggerTypes':
                        if type(documentInfo.result.__dict__[item]).__name__ == 'instance':
                            for key in documentInfo.result.__dict__[item].__dict__:
                                if key != 'swaggerTypes':
                                    if type(documentInfo.result.__dict__[item].__dict__[key]).__name__ == 'instance':
                                        for value in documentInfo.result.__dict__[item].__dict__[key].__dict__:
                                            if value != "swaggerTypes":
                                                result += "<tr><td>" +  value + "</td><td>" + unicode(documentInfo.result.__dict__[item].__dict__[key].__dict__[value]) + "</td></tr>"
                                    else:
                                        result += "<tr><td>" + key + "</td><td>" + unicode(documentInfo.result.__dict__[item].__dict__[key]) + "</td></tr>"
                        else:
                            result += "<tr><td>" + item + "</td><td>" + unicode(documentInfo.result.__dict__[item]) + "</td></tr>"
                result += "</table>"

    except Exception, e:
        return render_to_response('__main__:templates/sample45.pt',
                                  dict(error=str(e)))
Exemplo n.º 34
0
        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
    ### 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)
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    storage.basePath = basePath
    signature.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = storage.UploadWeb(clientId, url)
            guid = upload.result.guid
            try:
                ####Make a request to Storage API using clientId
Exemplo n.º 35
0
        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
    ### 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
Exemplo n.º 36
0
            file_path = os.path.join(currentDir + '/../downloads', the_file)
            try:
                #Delete file from folder
                os.unlink(file_path)

            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 ComparisonApi object
    compare = ComparisonApi(apiClient)
    api = StorageApi(apiClient)
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    api.basePath = basePath
    compare.basePath = basePath
    if url != "" or target_url != "":
        if url != "":
            try:
                # Upload file to current user storage using entere URl to the file
                upload = api.UploadWeb(clientId, url)
                sourceFileId = upload.result.guid

            except Exception, e:
                return render_to_response('__main__:templates/sample19.pt',
                    { 'error' : str(e) })
Exemplo n.º 37
0
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:
Exemplo n.º 38
0
            elif paramName == "guid":
                fileGuid = paramValue
            else:
                dataForMerge[paramName] = paramValue

        # Checking clientId and privateKey
        if not clientId or not privateKey:
            return render_to_response('__main__:templates/sample35.pt',
                                      dict(error='You do not enter your User Id or Private Key', newForm=""))
        ####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
        merge = MergeApi(apiClient)
        #Create DocApi object
        doc = DocApi(apiClient)
        #Check is base path entered
        if not 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
        merge.basePath = basePath
        doc.basePath = basePath