开发者

Take byte[] variable instead of direct local file path?

Rackspace Clo开发者_如何学Goud files, the PutStorageItem method is declared to take a local file path, can i use a variable instead?

API PutStorageItem(string ContainerName, string localFilePath);

My method is declared as

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 
}

As you can see, PutStorageItem takes a local string path, but Item is declared as byte[]. Can I use a variable instead of the local path?


If the Cloudfiles library gives you no alternative upload functions you have two main options:

  • Update your code to get a filename rather than pre-fetching the data.

Obviously this is only applicable if your are uploading files rather than storing generic data from some other system.

  • Grab a copy of the Couldfiles API library source code, then add an overload to take data rather than a filename and rebuild the library.

I've done number 2 in the past where I needed to set certain headers and the library code only allowed adding "meta" headers. If going down this route, the homepage can be found here, and the .Net bindings are on github here.

There is a final option which is more of a hack.

  • Save your byte[] a temporary file on disk (assuming you have access) then pass the filename to the Cloudfiles library.

Obviously, this last option is somewhat hacky and has issues with disk space and cleanup over time, especially if you are uploading large amounts of data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜