【问题标题】:Take byte[] variable instead of direct local file path?使用 byte[] 变量而不是直接的本地文件路径?
【发布时间】:2011-06-16 12:57:48
【问题描述】:

Rackspace Cloud 文件,PutStorageItem 方法被声明为采用本地文件路径,我可以使用变量来代替吗?

API PutStorageItem(string ContainerName, string localFilePath);

我的方法被声明为

UploadItem(string username, string apiKey, string ContainerName, byte[] Item)
{
  UserCredentials userCredentials = new UserCredentials(new Uri("https://auth.api.rackspacecloud.com/v1.0"), username, apiKey, null, null);

  Connection connection = new com.mosso.cloudfiles.Connection(userCredentials);

  connection.PutStorageItem(ContainerName, Item); //<--- X here 
}

如您所见,PutStorageItem 采用本地字符串路径,但 Item 被声明为 byte[]。 我可以使用变量而不是本地路径吗?

【问题讨论】:

    标签: c# asp.net string byte rackspace-cloud


    【解决方案1】:

    如果 Cloudfiles 库没有为您提供替代上传功能,您有两个主要选择:

    • 更新您的代码以获取文件名,而不是预取数据。

    显然,这仅适用于您上传文件而不是存储来自其他系统的通用数据的情况。

    • 获取 Couldfiles API 库源代码的副本,然后添加重载以获取数据而不是文件名并重建库。

    我过去做过第 2 项工作,我需要设置某些标头,而库代码只允许添加“元”标头。如果沿着这条路线走,可以找到主页here,.Net 绑定在github上here

    最后一个选项更像是一个 hack。

    • 将您的 byte[] 保存在磁盘上的一个临时文件(假设您有访问权限),然后将文件名传递给 Cloudfiles 库。

    显然,这最后一个选项有点老套,并且随着时间的推移会出现磁盘空间和清理问题,尤其是在您上传大量数据的情况下。

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 2021-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多