GVKun编程网logo

使用Python或Java从本地将数据上传到Azure ADLS Gen2(python上传数据到服务器)

15

如果您对使用Python或Java从本地将数据上传到AzureADLSGen2感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于使用Python或Java从本地将数据上传到Az

如果您对使用Python或Java从本地将数据上传到Azure ADLS Gen2感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于使用Python或Java从本地将数据上传到Azure ADLS Gen2的详细内容,我们还将为您解答python上传数据到服务器的相关问题,并且为您提供关于ADLS Gen2 资源的 Azure DevOps CI/CD 管道、asp.net – 上传到Azure、Azure DSC将Blob上传到Azure VM、Azure Functions :如何使用本地调试模式将日志写入 Azure Application Insights 和 Azure Functions 使用 Python?的有价值信息。

本文目录一览:

使用Python或Java从本地将数据上传到Azure ADLS Gen2(python上传数据到服务器)

使用Python或Java从本地将数据上传到Azure ADLS Gen2(python上传数据到服务器)

我在Data Lake Gen2中拥有一个Azure存储帐户。我想使用Python(或Java)将数据从本地上传到Lake Gen2文件系统。

我已经找到了有关如何与存储帐户中的文件共享进行交互的示例,但是我仍无法找到如何上传到Lake(而不是文件共享)的示例。我还发现了如何在Gen1
Lakes上执行此操作,但是除了已关闭的Gen2
请求外,什么都没有。

我的问题是,到今天为止,是否可以用Python做到这一点?或者,如何使用Java将文件上传到Gen2
Lake?演示用于上传的API调用的代码片段将受到高度赞赏。

答案1

小编典典

根据官方教程Quickstart: Upload, download, and list blobs withPython,如下所示,如果尚未注册Data Lake
Storage上的多协议访问的公共预览,则不能直接使用Python的Azure存储SDK在Azure
Data Lake Store Gen 2中进行任何操作。

注意

仅当您在Data Lake Storage上注册多协议访问的公共预览时,本文中介绍的功能才可用于具有分层名称空间的帐户。要查看限制,请参阅已知问题文章。

因此,将数据上传到ADLS Gen2的唯一解决方案是使用ADLS Gen2的REST API,请参阅其参考Azure Data Lake StoreREST API

这是我的示例代码,可以使用Python将数据上传到ADLS Gen2,并且工作正常。

import requestsimport jsondef auth(tenant_id, client_id, client_secret):    print(''auth'')    auth_headers = {        "Content-Type": "application/x-www-form-urlencoded"    }    auth_body = {        "client_id": client_id,        "client_secret": client_secret,        "scope" : "https://storage.azure.com/.default",        "grant_type" : "client_credentials"    }    resp = requests.post(f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token", headers=auth_headers, data=auth_body)    return (resp.status_code, json.loads(resp.text))def mkfs(account_name, fs_name, access_token):    print(''mkfs'')    fs_headers = {        "Authorization": f"Bearer {access_token}"    }    resp = requests.put(f"https://{account_name}.dfs.core.windows.net/{fs_name}?resource=filesystem", headers=fs_headers)    return (resp.status_code, resp.text)def mkdir(account_name, fs_name, dir_name, access_token):    print(''mkdir'')    dir_headers = {        "Authorization": f"Bearer {access_token}"    }    resp = requests.put(f"https://{account_name}.dfs.core.windows.net/{fs_name}/{dir_name}?resource=directory", headers=dir_headers)    return (resp.status_code, resp.text)def touch_file(account_name, fs_name, dir_name, file_name, access_token):    print(''touch_file'')    touch_file_headers = {        "Authorization": f"Bearer {access_token}"    }    resp = requests.put(f"https://{account_name}.dfs.core.windows.net/{fs_name}/{dir_name}/{file_name}?resource=file", headers=touch_file_headers)    return (resp.status_code, resp.text)def append_file(account_name, fs_name, path, content, position, access_token):    print(''append_file'')    append_file_headers = {        "Authorization": f"Bearer {access_token}",        "Content-Type": "text/plain",        "Content-Length": f"{len(content)}"    }    resp = requests.patch(f"https://{account_name}.dfs.core.windows.net/{fs_name}/{path}?action=append&position={position}", headers=append_file_headers, data=content)    return (resp.status_code, resp.text)def flush_file(account_name, fs_name, path, position, access_token):    print(''flush_file'')    flush_file_headers = {        "Authorization": f"Bearer {access_token}"    }    resp = requests.patch(f"https://{account_name}.dfs.core.windows.net/{fs_name}/{path}?action=flush&position={position}", headers=flush_file_headers)    return (resp.status_code, resp.text)def mkfile(account_name, fs_name, dir_name, file_name, local_file_name, access_token):    print(''mkfile'')    status_code, result = touch_file(account_name, fs_name, dir_name, file_name, access_token)    if status_code == 201:        with open(local_file_name, ''rb'') as local_file:            path = f"{dir_name}/{file_name}"            content = local_file.read()            position = 0            append_file(account_name, fs_name, path, content, position, access_token)            position = len(content)            flush_file(account_name, fs_name, path, position, access_token)    else:        print(result)if __name__ == ''__main__'':    tenant_id = ''<your tenant id>''    client_id = ''<your client id>''    client_secret = ''<your client secret>''    account_name = ''<your adls account name>''    fs_name = ''<your filesystem name>''    dir_name = ''<your directory name>''    file_name = ''<your file name>''    local_file_name = ''<your local file name>''    # Acquire an Access token    auth_status_code, auth_result = auth(tenant_id, client_id, client_secret)    access_token = auth_status_code == 200 and auth_result[''access_token''] or ''''    print(access_token)    # Create a filesystem    mkfs_status_code, mkfs_result = mkfs(account_name, fs_name, access_token)    print(mkfs_status_code, mkfs_result)    # Create a directory    mkdir_status_code, mkdir_result = mkdir(account_name, fs_name, dir_name, access_token)    print(mkdir_status_code, mkdir_result)    # Create a file from local file    mkfile(account_name, fs_name, dir_name, file_name, local_file_name, access_token)

希望能帮助到你。

ADLS Gen2 资源的 Azure DevOps CI/CD 管道

ADLS Gen2 资源的 Azure DevOps CI/CD 管道

如何解决ADLS Gen2 资源的 Azure DevOps CI/CD 管道?

我正在为 ADF、DataBricks 和 ADLS Gen2 等所有资源创建 CI/CD 管道。

我已经在 ADF 和 Databricks 上完成了 CI/CD,但看不到在 ADLS 资源上实现 CI/CD 的方法。

  1. 有什么方法可以在 ADLS 上实现 azure devops CI/CD 管道 gen2 资源?
  2. 如果无法使用直接方法,一旦我们的文件 必须存储在 ADLS 中的文件可在 github 存储库中找到,有没有办法将这些文件部署/复制到 ADLS 资源?

我在 ADLS 上没有看到任何关于 CI/CD 的文档/文章,所以在这里寻求帮助!

非常感谢任何线索!

解决方法

据我所知,没有办法将 blob 资源直接集成到 github 存储库中,但是您可以将文件添加到 git 存储库中,然后可以执行 AzureBlob 文件复制活动将这些文件复制到存储库中,如图所示下面。

提供容器名称和主文件夹位置(blob 前缀)并复制文件。 如果不存在存储库,此任务将尝试使用提供的名称创建一个新的存储库。

enter image description here

asp.net – 上传到Azure

asp.net – 上传到Azure

我在尝试直接将文件上传到azure blob存储时遇到问题.我正在使用ajax调用将发布请求发送到ashx处理程序以上传块中的blob.我遇到的问题是处理程序没有收到从ajax帖子发送的文件块.

我可以看到页面正在通过查看firebug中的请求正确接收帖子,

—————————–265001916915724 Content-disposition: form-data; >name=”Slice”; filename=”blob” Content-Type: application/octet-stream

我注意到处理程序上的输入流有文件块,包括请求中的其他字节.我试图从输入流中只读取文件块的大小,但这会导致文件损坏.

我从http://code.msdn.microsoft.com/windowsazure/Silverlight-Azure-Blob-3b773e26获得了灵感,我只是将它从MVC3转换为使用标准的aspx.

这是使用ajax将文件块发送到aspx页面的调用,

var sendFile = function (blockLength) {
var start = 0,end = Math.min(blockLength,uploader.file.size),incrimentalIdentifier = 1,retryCount = 0,sendNextChunk,fileChunk;
uploader.displayStatusMessage();
sendNextChunk = function () {
    fileChunk = new FormData();
    uploader.renderProgress(incrimentalIdentifier);
    if (uploader.file.slice) {
        fileChunk.append('Slice',uploader.file.slice(start,end));
    }
    else if (uploader.file.webkitSlice) {
        fileChunk.append('Slice',uploader.file.webkitSlice(start,end));
    }
    else if (uploader.file.mozSlice) {
        fileChunk.append('Slice',uploader.file.mozSlice(start,end));
    }
    else {
        uploader.displayLabel(operationType.UNSUPPORTED_broWSER);
        return;
    }
    var testcode = 'http://localhost:56307/handler1.ashx?create=0&blockid=' + incrimentalIdentifier + '&filename=' + uploader.file.name + '&totalBlocks=' + uploader.totalBlocks;
    jqxhr = $.ajax({
        async: true,url: testcode,data: fileChunk,contentType: false,processData:false,dataType: 'text json',type: 'POST',error: function (request,error) {
            if (error !== 'abort' && retryCount < maxRetries) {
                ++retryCount;
                setTimeout(sendNextChunk,retryAfterSeconds * 1000);
            }

            if (error === 'abort') {
                uploader.displayLabel(operationType.CANCELLED);
                uploader.resetControls();
                uploader = null;
            }
            else {
                if (retryCount === maxRetries) {
                    uploader.uploadError(request.responseText);
                    uploader.resetControls();
                    uploader = null;
                }
                else {
                    uploader.displayLabel(operationType.RESUME_UPLOAD);
                }
            }

            return;
        },success: function (notice) {
            if (notice.error || notice.isLastBlock) {
                uploader.renderProgress(uploader.totalBlocks + 1);
                uploader.displayStatusMessage(notice.message);
                uploader.resetControls();
                uploader = null;
                return;
            }

            ++incrimentalIdentifier;
            start = (incrimentalIdentifier - 1) * blockLength;
            end = Math.min(incrimentalIdentifier * blockLength,uploader.file.size);
            retryCount = 0;
            sendNextChunk();
        }
    });
};

非常感谢能帮到我的任何事情.

解决方法

是故意的ASPX吗?在 http://localhost:56307/handler1.ashx?create = 0& blockid?

Azure DSC将Blob上传到Azure VM

Azure DSC将Blob上传到Azure VM

xPSDesiredStateConfiguration文件夹/模块是否在同一目录中?它不随Windows一起提供,因此您需要从https://www.powershellgallery.com/packages/xPSDesiredStateConfiguration/8.10.0.0

获取

那是我一直使用的版本,工作正常。

Azure Functions :如何使用本地调试模式将日志写入 Azure Application Insights 和 Azure Functions 使用 Python?

Azure Functions :如何使用本地调试模式将日志写入 Azure Application Insights 和 Azure Functions 使用 Python?

如何解决Azure Functions :如何使用本地调试模式将日志写入 Azure Application Insights 和 Azure Functions 使用 Python??

我想将日志写入 Azure Application Insights,但不知道如何实现。
我需要更新我的 azure 函数 local.settings.jsonhost.json 文件吗??
另外,我是否需要使用 init.py 文件中的调用特定函数将我的日志写入 Azure Application Insights?
你能分享一些写日志的例子吗? 请注意 - 我的 Azure 函数使用的是 python。
谢谢

解决方法

这是host.json:

{
    "version": "2.0","logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,"excludedTypes": "Request"
            }
        }
    }
}

这是官方设置:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#applicationinsights

''applicationInsights.samplingSettings.isEnabled'' 是启用或禁用采样。

关于使用Python或Java从本地将数据上传到Azure ADLS Gen2python上传数据到服务器的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于ADLS Gen2 资源的 Azure DevOps CI/CD 管道、asp.net – 上传到Azure、Azure DSC将Blob上传到Azure VM、Azure Functions :如何使用本地调试模式将日志写入 Azure Application Insights 和 Azure Functions 使用 Python?的相关信息,请在本站寻找。

本文标签: