File Storage
Using the file storage to persist/retrieve large files or binary data
It is not recommended that you persist your binary data in your entities, it may slow down your application. For that purpose, the platform provides a File Service Interface to save/retrieve binary files that may be up to 50 GB.
The FileService is available from the inpaas.core.files
interface.
File Uploads
Use the FileService interface to persist binary or large data, the upload
method will return an id
that can be used to retrieve the data later on. You may want to store that id
in your entity, for that, use a Long
data type.
var fileId = require("inpaas.core.files").upload({
name: "hello-world.txt",
contentType: "text/plain",
data: "Hello World!"
});
return fileId;
That data
attribute could be a byte array, or a file uploaded to your web service. If you are receiving data in Base64 format, you may use the "b64" attribute:
var fileId = require("inpaas.core.files").upload({
name: "hello-world.txt",
contentType: "text/plain",
b64: "SGVsbG8gV29ybGQh"
});
return fileId;
Downloading Files
If you have the id
, generated from the upload
method, you may want to retrieve the data from the storage, use the download
method for that.
return require("inpaas.core.files").download(fileId);
Reading Text Data
You may also want to read large text files uploaded, for that purpose, there's a read
method which will read text files line-by-line:
var myData = []
var reader = require("inpaas.core.files").read(fileId, function(index, line) {
myData.push({ "ln": index, "text": line });
});
return myData;
Updated about 4 years ago