使用Azure函数输出文件 [英] Outputting a file with an Azure Function

查看:44
本文介绍了使用Azure函数输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Azure Functions.基本上我的用例是使用GUID作为GET参数调用该函数,让该函数下载WIX工具包DLL和MSI文件,更新MSI文件中的参数,然后将该文件返回给函数的调用者(下载时)提示).

I'm trying to experiment with Azure Functions. Basically my use case is calling the function with a GUID as GET Parameter, having the function download the WIX toolkit DLL and an MSI file, updating a parameter in the MSI file, and the returning that file to the caller of the function (as download prompt for example).

我大都在那儿,只需要一些帮助就可以完成下载提示/发送,到目前为止,我的代码是

I'm mostly there, just need some help getting the download prompt/send to happen, my code so far:

$urlWix = "http://domain/wix.dll"
$outputWix = "$Env:TEMP\wix.dll"

Invoke-WebRequest -Uri $urlWix -OutFile $outputWix
try{Add-Type -Path $outputWix}catch{$Null}
$urlMSI = "http://domain/file.msi"
$outputFile = "$Env:TEMP\file.msi"

Invoke-WebRequest -Uri $urlMSI -OutFile $outputFile

$oDatabase = New-Object Microsoft.Deployment.WindowsInstaller.Database($outputFile,[Microsoft.Deployment.WindowsInstaller.DatabaseOpenMode]::Direct);

$sSQLQuery = "SELECT * FROM Property WHERE Property= 'MYPROPERTY'"

[Microsoft.Deployment.WindowsInstaller.View]$oView = $oDatabase.OpenView($sSQLQuery)
$oView.Execute()

$oRecord = $oView.Fetch() 
$oRecord.SetString("Value","MyCustomValue")
$oView.Modify([Microsoft.Deployment.WindowsInstaller.ViewModifyMode]::Update,$oRecord)

$oView.Close();
$oDatabase.Dispose();
$file = get-item $outputFile
write-output $file

推荐答案

不幸的是,由于内容类型问题,这在Powershell中是不可能的.您可以通过C#,F#或Node( isRaw )函数.问题是您需要通过JSON响应格式指定标头,该标头会将所有非文本数据转换为base64字符串.

Unfortunately due to content type issues this is not possible in powershell. You can do this via a C#, F#, or Node (isRaw) function. The problem is that you need to specify headers via the JSON response format, which would convert any non-text data into a base64 string.

如果要通过Powershell发送文本文件,则可以:

If you want to sent a text file via powershell it is possible:

$response = ConvertTo-JSON @{
    Body="your file data";
    Headers=@{
        # unfortunately it seems functions does not support 'filename=...'
        'Content-Disposition'='attachment'; 
        # you would use application/octet-stream, but because it's converted to JSON you lose binary content
        'Content-Type'='text/plain';        
    };
}
Out-File -Encoding Ascii -FilePath $res -inputObject $response

这篇关于使用Azure函数输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆