Sessions is temporarily moving to YouTube, check out all our new videos here.


Nick Briscoe speaking at dotnetsheff in May, 2017
Great talks, fired to your inbox 👌
No junk, no spam, just great talks. Unsubscribe any time.

About this talk

Enchilada is a way to reference files in and between different providers (e.g. Azure, AWS, FTP, local...).


- Nick, I work at Razor. Let's talk to you today about a little library called Enchilada. Basically, it is, I'll just bring the code up for the actual library as well. Okay, so it's a file system abstraction layer. Now, I was working on a project where I had to use the Azure blob storage, SDK, and if anyone's ever used it, it's awful. It's not nice. Let me just find this. All right, there we go. So, I didn't want to use it. It's terrible. I'll show you a little example. Do do do do. There we go. So, if you look, you've got a set up all sorts of little things that I don't really care about. I've got to set up an account, a client, a container, it's like, I don't care. All I want to do is throw some bytes in a place and get them back later. That's all you want, isn't it? So, if we look through here, yeah, so set all this up. Create the container if it doesn't exist. Set up a stream to read in a file. Set the position of the stream back to zero. Create a block reference, set the name, upload from stream, it's just too much. And similarly, if you download a file, you have to block reference, create a place where you want to store it in file system, download the stream to that, sync it back to the origin. So I was fed up with doing this all the time. So, do do do do do. So I created Enchilada. And what it is is a way to reference files in and between different providers. So it could be local, Azure, AWS, FTP, anything, it doesn't care. So, what it consist basically of is a URI. Now, this is what you'd store in your database. So, yeah, I've got your scheme there. That's your way you want to store it. So if you look at the adapters. The adapter name corresponds to this little nugget here. Now, that can be anything, and the beauty of doing it this way is you can change what that points to without changing the URI. So suddenly cats wanted to be, I wanted to get it from FTP instead. I could just do, I could just do like this. Oops. Adapt name. And I would fill in the rest, and that's certainly acting in place of this. So no code in your application has to change at all. It's simply configuration. You can also, as I said, transfer files in between different providers without directly using their APIs. So you can say, okay, I've got a file system with cats in it, an FTP connexion, and blob storage, and I define the URIs of the files on those platforms. And whether or not they exist yet as well. So I want to copy this image to FTP and blob storage. There you go, done. And you can also copy between FTP and AWS, everything like that. I can show you if I get this open, do do do do do do, let's let this run. There's dot net core as well, which is all good. So if we look here, this is going from just step through those things. You see on the right, that copied it from file system to FTP and you can see all the commands there it sent on the right-hand side. If I look in, that's your storage emulator. Oh, the other one. Blob. I have cats. And don't have a cat yet. Oh, there we go, that's why. So copy from file system. There we go, and F10. We have copied it from local to blob storage and there we go. There you go, of course. So, yeah, so, that's a simple example. I've also got an example of how to use it in a web app. So if I just, where's my solution explorer now? All right. So I've got, I've built in ASP.NET Core DI support as well. So if I go into start up, you'll see here, I've just split this out a little, but this can be a one liner. Services at Enchilada, and tell it which configuration section. And if we look in the app settings, we have this little block here. And so, you can imagine in production, this would just be an environment setting or something like that. So I can say, this is local and I just run this. Upload a thing. I want to choose that one. So that's uploaded. If I look in temp, there we are. And if I go to, what's it called? Download. So if I send that, I should give me a backstream, and I can download it. There we go. So that's all using local and Enchilada. So, I'll just give you a good look at the upload. So, we inject an I into the file system resolver. That's all we have to do there. We construct a file path. So, I know it's cats 'cause this is the only end point I use for uploading cats. Open a read stream. So this doesn't care where you're getting the file from. Well, sorry, where you're putting the file. Open the file reference, copy it from the iPhone file, which is the NBC file upload mechanism. Okay, so if I suddenly desired to upload this to FTP, just replace that, and notice the adapter name's the same. Just close that. Run again. Open it. Just delete this. Oop, not again. Okay. So, now we're using hopefully Azure, yup. So if I select that image again. Upload it. We should see. Yes, I did, didn't I? Well, you'll see, there we go. Instead, it's gonna activate, that's the beauty of it, isn't it? Because it can be anything, it doesn't care. Yup, there we go, so loaded that file. Where has it gone? It was the third example that was the Azure, wasn't it? Do do do do do. So that's now Azure using local storage. There we go, so start that up again. And I said, this would just be an environment string in your production. That's the way we do it. So if we get that running, something like that, and upload it, you notice no code changes and what's going on here? Sorry? Oh, yeah, of course. Ah, of course, I always forget that. And there we go. There we go. So, yeah, that's my little library. I hope it's useful. I found it useful in a fairly decently sized system where we were migrating from local storage on a disc, on a network drive somewhere to a Azure-hosted scenario. And that made things much easier. And we're using that actively in that as well. It is battle hardened, in a sense. So we've use it a fair amount there. All right, that's it. If you go on GitHub, Spark, and Enchilada, I'll post a link dot net chef. Yeah, so there's FTP local and Azure, planning on do AWS and things like that in the future. So, yeah. It is all stream based. I haven't tried that. But I can't see why it wouldn't work. So you can get a constant stream from Twitter, or something. Stream and API. Yeah, yeah, absolutely, yeah. Keep an active connexion. Keep it going there. It's all stream based, like I say. So it should work, yeah. Any other questions? No, cool.