【问题标题】:How could we download Images By a URl from a table in PowerShell我们如何从 PowerShell 中的表中通过 URl 下载图像
【发布时间】:2021-08-12 05:17:33
【问题描述】:

在一个存储过程中,我有 5 列:

如何从 SQL Server 表中提供的 URL 下载图像。附截图中的表格结构。

我正在使用这个 PowerShell 脚本:

param (
        [string]$DatabaseServer = "codb01d.brandmuscle.local"
)
################## OrderReportExport ################

Import-Module JAMS
 $FileServerDestination = "C:\Temp\$(New-Guid)\"
 New-Item $FileServerDestination -itemType directory

 $OrderReportexport = $FileServerDestination+"OrderReport.csv"

# run reports
#sqlcmd -S $DatabaseServer -E -d "CentivPOS" -Q "Exec [dbo].[SE-OrderReport]" -o $OrderReportexport -W -s ","

function DataResults
{
$sql =@" 
exec [dbo].[LoationImagedata] 
"@
    
    Invoke-Sqlcmd -ServerInstance $Databaseserver -Database "Centiv" -Query $sql -QueryTimeout "2000"
    }

DataResults  

【问题讨论】:

  • 请不要编辑提供的答案以显示您的代码不起作用。如果可以,请添加评论,如果不能更新您的问题。

标签: sql-server powershell


【解决方案1】:

首先,您需要找到指向图像的最终 URI。 点赞:https://imagerepo.com/some/image.png

然后您可以使用Invoke-Webrequest cmdlet 下载它:

Invoke-WebRequest -Uri https://imagerepo.com/some/image.png -OutFile C:\image.png

上传到SQL可以参考this:

[Byte[]]$file = get-content -Encoding Byte C:\TEMP\pictures\image1.jpg
$hexString = ($file|ForEach-Object ToString X2) -join ''
$hexString = '0x'+$hexString 

$cmd.CommandText ="UPDATE QuoteData SET PII_Image1 = $hexString Where QuoteNumber =  '"+$WorkSheet.Range('G7').Text.replace("'","''")+"'"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    • 2017-10-25
    • 2016-11-03
    • 1970-01-01
    • 2017-01-31
    相关资源
    最近更新 更多