Magentrix provides a sophisticated yet easy way to access files on the cloud via the Storage class. The Storage system uses a delegated approach, allowing you to keep the file metadata in any Entity and store the actual file in the Cloud Storage System. In order to work with cloud files, you can use the "Storage" class in your Active Classes.
The Storage class provides the following methods:
- ReadFile(string blobId) : Stream
Returns a special stream that can be used with the Custom Controller's File response.
- ReadFileBytes(string blobId) : byte
Suitable for smaller files when you want to convert the file into PDF or stream it back to the client<s browser.
- GetFileInfo(string blobId) : Blob
Returns a Blob class, which provides you with detail information about the file.
- WriteFile(string blobId, byte fileContents) : long
BlobId is a unique Id for the file which is used to retrieve the file.
- WriteFile(string blobId, byte fileContents, object attributes): long
BlobId is a unique identifier to fetch the file later on and attributes is a class object which has properties you need to store with the file.
- DeleteFile(string blobId) : void
Deletes a file from the Magentrix cloud storage.
- ReplaceFile(string blobId, byte newFileContents) : long
Locates a file by blobId and replaces its contents with the new file contents provided.
Below is an example that allows the user to upload a file and store it in Magentrix Storage system:
public ActionResponse SaveFile(HttpPostedFile myFile)
return Content("File saved!");
See FieldFileUpload for more information.
The example below shows how you can read a file from your Storage system and stream it back to the requester:
public ActionResponse Download(string fileId)
return StorageFile(fileId, MimeContentTypes.Word, "myfileName.doc");
See MimeContentTypes class for other MIME type options and StorageFile response for possible Storage file streaming options.