使用 PowerShell v3 的 Invoke-RestMethod 来 PUT/POST X Mb 的二进制文件 [英] Using PowerShell v3's Invoke-RestMethod to PUT/POST X Mb of a binary file

查看:34
本文介绍了使用 PowerShell v3 的 Invoke-RestMethod 来 PUT/POST X Mb 的二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 PowerShell v3(来自 此处)及其新的 Invoke-RestMethod 如下所示:

I have been doing a bit of work with PowerShell v3 (CTP2 from here) and its new Invoke-RestMethod like so:

Invoke-RestMethod -Uri $dest -method PUT -Credential $cred -InFile $file

Invoke-RestMethod -Uri $dest -method PUT -Credential $cred -InFile $file

但是,我想用它来推送非常 大的二进制对象,因此喜欢能够从一个大的二进制文件中推送范围的字节.

However, I'd like to use this for pushing very large binary objects, and therefore like be able to push a range of bytes from a large binary file.

例如,如果我有一个 20Gb 的 VHD,我想把它分成几个块,比如每个块 5Gb(不先拆分和保存单个块),然后将它们放置/发布到 BLOB 存储,如 S3、Rackspace,Azure 等.我还假设块大小大于可用内存.

For example, if I have a 20Gb VHD, I would like to break it up into chunks of say, 5Gb each (without splitting and saving the individual chunks first) and PUT/POST these to BLOB storage like S3, Rackspace, Azure, etc. I am also assuming the chunk size is larger than the available memory.

我读过 Get-Content 在大型二进制文件上的工作效率不高,但这似乎不是一个模糊的要求.有没有人有任何可以用于此的方法,特别是与 PowerShell 的新 Invoke-RestMethod 结合使用?

I've read Get-Content does not work very efficiently on large binary files, but this doesn't seem like an obscure requirement. Does anyone have any appraoches which could be used for this, particularly in conjunction with PowerShell's new Invoke-RestMethod?

推荐答案

我相信您正在寻找的 Invoke-RestMethod 参数是

I believe the Invoke-RestMethod parameter you're looking for is

-TransferEncoding Chunked

但无法控制块或缓冲区大小.如果我错了,有人可以纠正我,但我认为块大小是 4KB.每个块都被加载到内存中然后发送,因此您的内存不会被您发送的文件填满.

but there is no control over the chunk or buffer size. Someone can correct me if I am wrong, but I think the chunk size is 4KB. Each chunk gets loaded into memory and then sent, so you memory doesn't fill up with the file you are sending.

这篇关于使用 PowerShell v3 的 Invoke-RestMethod 来 PUT/POST X Mb 的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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