示例#1
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)})