如何使用Windows服务将文件上传到rackspace云

发布于 2024-10-07 15:30:49 字数 294 浏览 5 评论 0原文

使用我的 Windows 服务(目标框架=.Net Framework 4.0 客户端配置文件)我尝试将文件上传到机架空间云文件。

我在这里找到了一些 asp.net c# api https://github.com/rackspace/csharp-cloudfiles

但看起来它们与 Windows 服务不兼容。

有什么线索可以让这一切一起工作吗?

using my windows service (target framework=.Net framework 4.0 client profile) I am trying to upload files to rackspace cloudfiles.

I found out some asp.net c# apis here https://github.com/rackspace/csharp-cloudfiles

but looks like they are not compatible with windows services.

any clues how to make this work together?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜尕妞 2024-10-14 15:30:49

它是与rackspce 一起使用的完美库。我正在用它。我确信在 Windows 服务中使用这个库没有问题。但我认为 .net Framework 客户端配置文件和 com.mosso.cloudfiles.dll 可能存在问题。但首先尝试使用客户资料。

另外,我使用以下代码将文件上传到 Rackspace(Configuration 这是我的配置类。而不是使用您自己的凭据,而不是“Configuration.RackSpaceUserName”和“Configuration.RackSpaceKey”):

  private Connection CreateConnection()
        {
            var userCredentials = new UserCredentials(Configuration.RackSpaceUserName, Configuration.RackSpaceKey);
            return new Connection(userCredentials);
        }

  public void SaveUniqueFile(string containerName, string fileName, Guid guid, byte[] buffer)
        {
            string extension = Path.GetExtension(fileName);
            Connection connection = CreateConnection();
            MemoryStream stream = new MemoryStream(buffer);
            string uniqueFileName = String.Format("{0}{1}", guid, extension);
            connection.PutStorageItem(containerName, stream, uniqueFileName);
        }

配置如下:

public class Configuration
{
  public static string RackSpaceUserName = "userName";
  public static string RackSpaceKey= "rackspaceKey";
}

我您不想使用 com .mosso.cloudfiles.dll 非常容易为机架空间创建您自己的驱动程序。因为实际上要将文件上传到机架空间,您只需要发送带有“X-Auth-Token”标头的放置请求。您还可以使用 firefox 插件 检查请求结构,查看文件并将其上传到 Rackspace 和 firebug

It's perfect library for work with rackspce. I am use it. And i am sure that it's not problem to use this library inside of windows service. But i think possible problems with .net framework client profile and com.mosso.cloudfiles.dll. But try first with client profile.

Also i use following code to upload files to Rackspace(Configuration it's my configuration class. Instead of 'Configuration.RackSpaceUserName' and 'Configuration.RackSpaceKey' use yous own creadentials):

  private Connection CreateConnection()
        {
            var userCredentials = new UserCredentials(Configuration.RackSpaceUserName, Configuration.RackSpaceKey);
            return new Connection(userCredentials);
        }

  public void SaveUniqueFile(string containerName, string fileName, Guid guid, byte[] buffer)
        {
            string extension = Path.GetExtension(fileName);
            Connection connection = CreateConnection();
            MemoryStream stream = new MemoryStream(buffer);
            string uniqueFileName = String.Format("{0}{1}", guid, extension);
            connection.PutStorageItem(containerName, stream, uniqueFileName);
        }

Configuration something like this:

public class Configuration
{
  public static string RackSpaceUserName = "userName";
  public static string RackSpaceKey= "rackspaceKey";
}

I you don't want to use com.mosso.cloudfiles.dll very easy create you own driver for rackspace. Because actually for upload file to rackspace you just need send put request with 'X-Auth-Token' header. Also you can check request structure using plugin for firefox to view and upload files to Rackspace and firebug.

笛声青案梦长安 2024-10-14 15:30:49

我在这里有一些使用相同库的 C# 示例:

https://github.com/chmouel /upload-to-cf-cs

这是一个非常简单的 CLI,但希望它能让您了解如何使用它。

I have some example in C# using that same library here :

https://github.com/chmouel/upload-to-cf-cs

this is a pretty simple CLI but hopefully that should give an idea how to use it.

删除→记忆 2024-10-14 15:30:49

我已经研究这个问题大约一个小时了,VS2010 中发生了奇怪的事情。虽然我已经引用了 dll 并且智能感知正在工作,但无法编译。

看起来引用的 dll 消失了。因此,如果您遇到同样的问题,我建议您使用 .NET 3.5 的机架空间:csharp-cloudfiles-DOTNETv3.5-bin-2.0.0.0.zip

请务必将您的项目更改为相同的框架版本。效果真的很好。

供您参考,下载页面位于:https://github.com/rackspace/csharp-cloudfiles /下载

I've been around this for about one hour and weird things are happening into VS2010. Although I have referenced the dll and intellisense is working, cannot compile.

It looks like the referenced dll disappears. So, my recomendation in case you go into the same issue, use rack space for .NET 3.5: csharp-cloudfiles-DOTNETv3.5-bin-2.0.0.0.zip

Just be sure to change your project to the same framework version. It works really good.

For your reference, the downloads page is here: https://github.com/rackspace/csharp-cloudfiles/downloads

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文