how to upload files to rackspace cloud using windows services - windows-services

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?

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.

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.

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

Related

How to download all files in an Azure Container Directory?

I have an aspnet app which i upload files to the azure blobs. I know that azure don't create structural paths in the containers, just blobs, but you can emulate directories putting a "/" on the uri.
i.e
I'd upload a list of files and my uri is like this
http://myaccount.windowsazure.blob.net/MyProtocolID-01/MyDocumentID-01/FileName01.jpg
http://myaccount.windowsazure.blob.net/MyProtocolID-01/MyDocumentID-01/FileName02.jpg
http://myaccount.windowsazure.blob.net/MyProtocolID-01/MyDocumentID-01/FileName03.jpg
My download method:
public RemoteFile Download(DownloadRequest request)
{
var fileFinal = string.Format("{0}/{1}/{2}",request.IDProtocol ,request.IDDocument, request.FileName);
var blobBlock = InitializeDownload(fileFinal);
if (!blobBlock.Exists())
{
throw new FileNotFoundException("Error");
}
var stream = new MemoryStream();
blobBlock.DownloadToStream(stream);
return File(request.FileName)
}
private CloudBlob InitializeDownload(string uri)
{
var blobBlock = _blobClient.GetBlobReference(uri);
return blobBlock;
}
This way, i'm getting just one file. But i need to see and download all files inside http://myaccount.windowsazure.blob.net/MyProtocolID-01/MyDocumentID-01/
Thanks
Adding more details. You will need to use one of the listing APIs provided by the client library: CloudBlobContainer.ListBlobs(), CloudBlobContainer.ListBlobsSegmented(), and CloudBlobContainer.ListBlobsSegmentedAsync() (and various overloads.). You can specify the directory prefix, and the service will only enumerate blobs matching the prefix. You can then download each blob. You may also want to look at the ‘useFlatBlobListing’ argument, depending on your scenario.
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx
In addition AzCopy (see http://blogs.msdn.com/b/windowsazurestorage/archive/2012/12/03/azcopy-uploading-downloading-files-for-windows-azure-blobs.aspx) also supports this scenario of downloading all blobs in a given directory path.
Since each blob is a separate web resource, function above will download only one file. One thing you could do is list all blobs using the logic you are using and then download those blobs on your server first, zip them and the return that zip file to your end user.
Use AzCopy functionalities, now, it has a lot of supports.
https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10

sqlite-net fails to create database in MonoDroid application

I start Xamarin Studio 4.0.3 and create a new solution for MonoDroid application. I am targetting version 2.3 or higher. I include Sqlite.cs from the sqlite-net (latest from site) project. I make sure I have a reference to Mono.Data.SQLite in the project. Then in the OnCreate of the default MainActivity I try to use the code shown in the readme to make a database connection:
string path = Android.OS.Environment.DataDirectory.ToString();
string dbname = path + "/" + "test.db3";
var db = new SQLiteConnection(dbname, SQLiteOpenFlags.Create|SQLiteOpenFlags.ReadWrite ,true);
However it always fails with an exception saying it can't open the database. If I follow Greg Shackles example and use SqliteDbHelper method it works, but I would like to understand what I am doing wrong that sqlite-net connection method is not working. I have a feeling I am missing something simple. I did also try just passing in a filename to SQLiteConnection() as well but when it failed I added the OpenFlags to see if that was the issue.
I just found out that apparently you're supposed to use the personal folder, instead of the databases folder:
string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var db = new SQLiteConnection(Path.Combine(folder, "mydb.db"));

Setting/overriding an app deployment folder

Is there a way to set or override a project deployment folder in Mono for Android? For example, my application right now deploys to /data/data/SolutionEngine/files/.__override__
The nature of the application is that it loads plug-ins using Reflection, and by default it looks in the /Adapters sub-folder from the app root. This is how it works on the desktop and the Compact Framework, so for simplicity we'd like to continue to do the same on Android.
If I have a single solution that has the app and some plug-ins in it, I'd like those files to get deployed in the proper structure when I start debugging.
You could write out the plugins as android assets (see screenshot below). Please Note: You might need to change the extension to .mp3. See here. I didn't have this issue though.
Once you do that, you should be able to get the assets by using the Asset Manager. You can copy them to a different folder or do whatever with them. Here is a sample of reading them into memory and them writing out the name.
const String pluginPath = "Plugins";
var pluginAssets = Assets.List(pluginPath);
foreach (var pluginAsset in pluginAssets)
{
var file = Assets.Open(pluginPath + Java.IO.File.Separator + pluginAsset);
using (var memStream = new MemoryStream())
{
file.CopyTo(memStream);
//do something fun.
var assembly = System.Reflection.Assembly.Load(memStream.ToArray());
Console.WriteLine(String.Format("Loaded: {0}", assembly.FullName));
}
}

FTP client code in BlackBerry

I have been trying to download a file from an FTP server to the sdcard of the simulator through a FTP client. I have not been able to find a reference for how to code an FTP client. Can anyone please help or provide me a link where I can get a sample code of how to download a file using FTP? When I was working in an Android environment, I made use of an external jar file for FTP, but in Blackberry that same jar file is of no use.
Here is a sample code..
public final class UploadScreen extends MainScreen
{
File f;
public UploadScreen()
{
setTitle("File Upload");
SimpleFTP ftp=new SimpleFTP();
try {
ftp.connect("14.97.146.41/xml/", 21);
ftp.bin();
f=new File("asd");
boolean a=ftp.stor(f);
if(a)
{
Dialog.alert("Done");
}
else
{
Dialog.alert("Fail");
}
ftp.disconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Here simpleftp is a jar file that i have downloaded from "http://www.jibble.org/simpleftp/"
Now here when i run this prog. it doesn't even run and crashes saying Module "SimpleFTP" not found.I have added external jar file to the project but still its not working. I read about preverfiying the jar files but when i try to do that from command prompt, it says
Error preverifying class org.jibble.simpleftp.SimpleFTP
java/lang/NoClassDefFoundError: java/lang/Object
Please help this code is fro uploading but i have same problems for downloading
BlackBerry devices use Java-ME, and not Java-SE. This is in contrast to Android devices, which are able to make use of unmodified Java-SE libraries.
At the language level, Java-ME requires Java 1.3 language compliance - this means no generics, no assert, no enums. Most modern Java libraries use at least one of those features, but maybe you got lucky with SimpleFTP.
At the API level, Java-ME does not use the standard networking classes from Java-SE. Instead you will have to use Connector and cast the result to a StreamConnection. This is substantially different than what a Java-SE library will be doing.

Open pdf in browser plugin

How do I (in my controller) send a pdf that opens in the browser. I have tried this but it only downloads the file (both ie and firefox) without asking.
public ActionResult GetIt()
{
var filename = #"C:\path\to\pdf\test.pdf";
// Edit start
ControllerContext.HttpContext.Response.AddHeader("Content-Disposition", String.Format("inline;filename=\"{0}\"", "test.pdf"));
// Edit stop
return File(filename, "application/pdf", Server.HtmlEncode(filename));
}
After adding the edit above it works as it should, thanks.
You need to set the Content disposition HTTP header to inline to indicate to the browser that it should try to use a PDF plugin if it is available.
Something like: Content-Disposition: inline; filename=test.pdf
Note that you cannot force the use of the plugin, it is a decision made by the browser.
This (in addition to the other headers) does the trick for me in a plain .net web app:
Response.AddHeader("Content-Disposition", String.Format("inline;filename=""{0}""", FileName))
I'm not familiar with MVC, but hopefully this helps.
I think this relies on how the client handles PDF files. If it has setup to let Adobe Reader open the files in the browser plugin it will do that, but maybe you have set it up to download the file rather than opening it.
In any case, there is no way of controlling how PDF files will be opened on the user's machine.

Resources