コード例 #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)})
コード例 #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) })
コード例 #3
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)})
コード例 #4
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) })
コード例 #5
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:
コード例 #6
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)})
コード例 #7
0
    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

                #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/sample21.pt',
                                          {'error': str(e)})
            fileId = ""
        except Exception, e:
            return render_to_response('__main__:templates/sample21.pt',
                                      {'error': str(e)})