Storage¶
Items
Meaning of Storage¶
Storage is a functionality, which consolidates the files (Mainly data files) to be shared by uploaded file or system while using intra-mart Accel Platform on distributed system.Note
When developing distributed system, a directory to be shared by each Web Application Server should be configured.Refer “Set up Guide” for the details.
Types of Storage¶
SystemStorage
It is an area where the files used by the system are saved.It is mainly used for the process within base API or application of intra-mart Accel Platform.PublicStorage
It is an area to save an uploaded file or a file to be shared among the users.When saving a file in storage, essentially save it in PublicStorage.SessionScopeStorage
It is an area to save the file temporarily.It is used for temporarily saving the file or the stored data uploaded during processing.The file saved in SessionScopeStorage is auto-deleted when the session expires.
Streaming¶
In intra-mart Accel Platform, the data saved in Storage can be used in stream.Large files can be uploaded and downloaded by using stream, without saving the file data in the memory of Web Application Server as in the earlier intra-mart WebPlatform.Note
When load (), read (), save (), write () methods of storage API are used, the memory is compressed as the file data is deployed in the memory of AP server.Therefore using such methods is not recommended.
Programming Techniques¶
File Upload¶
Here, uploading of file in “sample” directory in PublicStorage is shown./** * Uploads the file to publicStorage "sample" directory. * @param request request object */ function init(request) { // Acquires uploaded file. var upfile = request.getParameter("local_file"); // Acquires the binary stream of uploaded file. upfile.openValueAsBinary(function(reader) { // Creates the PublicStorage object wherein the destination to save the file is specified. var storage = new PublicStorage("sample", upfile.getFileName()); // Generates the binary stream of the save destination. storage.createAsBinary(function(writer, error) { if(error) { // Exception handling is done when binary stream of the save destination could not be generated. } else { // Writes the uploaded file in PublicStorage. reader.transferTo(writer); } }); }); }
File Download¶
Here, downloading of “sample.txt” file in PublicStorage is shown./** * Send sample.txt to client. * @param request Request Object */ function init(request) { var storage = new PublicStorage("sample.txt"); if(!storage.isFile()) { // When file does not exist exception handling is done. } else { // Send the file to client. Module.download.send(storage, storage.getName(), "text/plain"); } }