Hi Sameera,
At the end, this is what actually worked... Sending the code snippet for
record..
<%
var carbon = require('carbon');
var datasetService =
carbon.server.osgiService('org.wso2.carbon.ml.dataset.DatasetService');
var uploadingDir = datasetService.getDatasetUploadingDir();
var file = request.getFile("uploadDataset");
var uploadFilePath = 'file:///'+uploadingDir+"/"+file.getName();
var fileN = new File(uploadFilePath);
try{
file.open('r');
fileN.open('w');
fileN.write(file.getStream());
}
finally{
fileN.close();
file.close();
}
%>
Thanks.
On Wed, Oct 8, 2014 at 3:15 PM, Sameera Medagammaddegedara <
[email protected]> wrote:
> Hi Lochana,
>
> As per our offline discussion you could try the following:
>
> <%
> var systemProcess = require('process');
> var parent = 'file:///' + (systemProcess.getProperty('
> jaggery.home') ||
> systemProcess.getProperty('carbon.home')).replace(/[\\]/g,
> '/').replace(/^[\/]/g, '');
> print(parent);
> var file=new File(parent+'/test.txt');
> try{
> file.open('w');
> file.write('hello!');
> }catch(e){
> print(e);
> } finally{
> file.close();
> }
> %>
> Thank You,
> Sameera
>
> On Tue, Oct 7, 2014 at 12:50 PM, Chan <[email protected]> wrote:
>
>> I believe it's because Jaggery Apps are web apps that needs to operate
>> under the deployments directory. Writing into other directories of the
>> server is potentially harmful and a bad practice. But I do understand the
>> testing part (since it's easy to save a file to filesystem). How about
>> having a special folder inside the webapp (like 'files') and saving them to
>> that location. Saving part needs to be abstracted away so that it can be
>> later switched to some other implementation.
>>
>> Also I think you need to read this file from a Java component. For that -
>> you can use the absolute path to the web app itself (again the same method
>> as above -abstract the implementation)
>>
>> @SameeraM @SameeraP remember the file server discussion we had couple of
>> months ago. I think - now we need to have a platform wide, scalable, secure
>> standard to write to files and read files.
>>
>> Cheers~
>>
>> On Tue, Oct 7, 2014 at 12:41 PM, Lochana Menikarachchi <[email protected]>
>> wrote:
>>
>>> Is there any reason to restrict file system operations (why not outside
>>> Jaggery application context root) ?
>>> http://jaggeryjs.org/documentation.jag?api=file
>>>
>>> On Tue, Oct 7, 2014 at 12:20 PM, Lochana Menikarachchi <[email protected]
>>> > wrote:
>>>
>>>> We need to support file uploading to a server location (for testing
>>>> etc.) in addition to S3,HDFS etc.
>>>>
>>>> My question is why does file.save do it the way it does..
>>>>
>>>> Operation Returns Description File(String filename)Object
>>>>
>>>> var file = new File("/templates/tmp.jag");
>>>>
>>>> Takes a filename and provides a File object. (File path is relative to
>>>> the Jaggery application context root)
>>>>
>>>> shouldn't it allow saving to any location..
>>>>
>>>>
>>>> On Tue, Oct 7, 2014 at 12:11 PM, Chan <[email protected]> wrote:
>>>>
>>>>> Hi Lochana,
>>>>> Exactly. The correct method to store files is to use a separate file
>>>>> service (S3) or use HDFS/RDMS to store the files. Adding @sameeraM to the
>>>>> thread.
>>>>>
>>>>> Cheers~
>>>>>
>>>>> On Tue, Oct 7, 2014 at 12:09 PM, Lochana Menikarachchi <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> >>File uploading brings about a number of issues in scalability. For
>>>>>> example - if we upload files to the deployments directory- it's not going
>>>>>> to scale properly (DepSync will sync all these files across the cluster
>>>>>> if
>>>>>> DepSync enabled).
>>>>>>
>>>>>> This is exactly what is happening with current file save method,
>>>>>>
>>>>>> if you do following:
>>>>>>
>>>>>> var carbon = require('carbon');
>>>>>> var datasetService =
>>>>>> carbon.server.osgiService('org.wso2.carbon.ml.dataset.DatasetService');
>>>>>> var uploadingLimit = datasetService.getDatasetUploadingLimit();
>>>>>> var memThreshold = datasetService.getDatasetInMemoryThreshold();
>>>>>> var uploadingDir = datasetService.getDatasetUploadingDir();
>>>>>> var file = request.getFile("uploadDataset");
>>>>>> * file.saveAs(uploadingDir+"/"+file.getName());*
>>>>>>
>>>>>> file gets saved under deployment directory.
>>>>>>
>>>>>> We need to upload the file into some other directory on the server..
>>>>>>
>>>>>>
>>>>>> On Tue, Oct 7, 2014 at 11:44 AM, Chan <[email protected]> wrote:
>>>>>>
>>>>>>> Hi Lochana,
>>>>>>> File uploading brings about a number of issues in scalability. For
>>>>>>> example - if we upload files to the deployments directory- it's not
>>>>>>> going
>>>>>>> to scale properly (DepSync will sync all these files across the cluster
>>>>>>> if
>>>>>>> DepSync enabled). Also saving a file to a specific path is inadvisable
>>>>>>> cause paths will depend upon deploying machine.
>>>>>>>
>>>>>>> Can you elaborate more on the requirement - where we can give a
>>>>>>> solution?
>>>>>>>
>>>>>>> Cheers~
>>>>>>>
>>>>>>> On Tue, Oct 7, 2014 at 10:50 AM, Lochana Menikarachchi <
>>>>>>> [email protected]> wrote:
>>>>>>>
>>>>>>>> Unfortunately, that's not going to work. Shouldn't there be a file
>>>>>>>> uploader in jaggery (that can upload a file to a given location)?
>>>>>>>>
>>>>>>>> On Tue, Oct 7, 2014 at 10:45 AM, Dilan Udara Ariyaratne <
>>>>>>>> [email protected]> wrote:
>>>>>>>>
>>>>>>>>> Hi Lochana!
>>>>>>>>>
>>>>>>>>> Do not know exactly whether their is a way to directly
>>>>>>>>> give an absolute path and save the file.
>>>>>>>>>
>>>>>>>>> BTW, as a workaround, if no such way exists, can you try to create
>>>>>>>>> the corresponding relative path for the given absolute one
>>>>>>>>> and use the same method provided.
>>>>>>>>>
>>>>>>>>> Cheers!
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> *Dilan U. Ariyaratne*
>>>>>>>>> Software Engineer
>>>>>>>>> WSO2 Inc. <http://wso2.com/>
>>>>>>>>> Mobile: +94775149066
>>>>>>>>> lean . enterprise . middleware
>>>>>>>>>
>>>>>>>>> On Tue, Oct 7, 2014 at 10:29 AM, Lochana Menikarachchi <
>>>>>>>>> [email protected]> wrote:
>>>>>>>>>
>>>>>>>>>> Dilan, There is a specific requirement.. We need to upload a file
>>>>>>>>>> to a given location
>>>>>>>>>> Madhuka, That method returns absolute path.. What I want is to
>>>>>>>>>> upload a file to a given location (that is when absolute path is
>>>>>>>>>> given as a
>>>>>>>>>> string)
>>>>>>>>>> Thanks.
>>>>>>>>>>
>>>>>>>>>> On Tue, Oct 7, 2014 at 9:55 AM, madhuka udantha <
>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> you can do it. absolute path
>>>>>>>>>>>
>>>>>>>>>>> var absolute = function (path) {
>>>>>>>>>>> var systemProcess = require('process');
>>>>>>>>>>> var parent = 'file:///' +
>>>>>>>>>>> (systemProcess.getProperty('jaggery.home') ||
>>>>>>>>>>> systemProcess.getProperty('carbon.home')).replace(/[\\]/g,
>>>>>>>>>>> '/').replace(/^[\/]/g, '');
>>>>>>>>>>> return parent + MODULE_PATH + path;
>>>>>>>>>>> };
>>>>>>>>>>>
>>>>>>>>>>> [1]
>>>>>>>>>>> https://github.com/Madhuka/sugarcane/blob/master/core/sugarcane/scripts/engine/test.js
>>>>>>>>>>> On Tue, Oct 7, 2014 at 9:37 AM, Lochana Menikarachchi <
>>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> Cheers,
>>>>>>>>>>> Madhuka Udantha
>>>>>>>>>>> http://madhukaudantha.blogspot.com
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> Lochana Menikarachchi
>>>>>>>>>> Senior Tech Lead
>>>>>>>>>> WSO2 Inc.
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> Dev mailing list
>>>>>>>>>> [email protected]
>>>>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Lochana Menikarachchi
>>>>>>>> Senior Tech Lead
>>>>>>>> WSO2 Inc.
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> Dev mailing list
>>>>>>>> [email protected]
>>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Chan (Dulitha Wijewantha)
>>>>>>> Software Engineer - Mobile Development
>>>>>>> WSO2 Inc
>>>>>>> Lean.Enterprise.Mobileware
>>>>>>> * ~Email [email protected] <[email protected]>*
>>>>>>> * ~Mobile +94712112165 <%2B94712112165>*
>>>>>>> * ~Website dulitha.me <http://dulitha.me>*
>>>>>>> * ~Twitter @dulitharw <https://twitter.com/dulitharw>*
>>>>>>> *~Github @dulichan <https://github.com/dulichan>*
>>>>>>> *~SO @chan <http://stackoverflow.com/users/813471/chan>*
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Lochana Menikarachchi
>>>>>> Senior Tech Lead
>>>>>> WSO2 Inc.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Chan (Dulitha Wijewantha)
>>>>> Software Engineer - Mobile Development
>>>>> WSO2 Inc
>>>>> Lean.Enterprise.Mobileware
>>>>> * ~Email [email protected] <[email protected]>*
>>>>> * ~Mobile +94712112165 <%2B94712112165>*
>>>>> * ~Website dulitha.me <http://dulitha.me>*
>>>>> * ~Twitter @dulitharw <https://twitter.com/dulitharw>*
>>>>> *~Github @dulichan <https://github.com/dulichan>*
>>>>> *~SO @chan <http://stackoverflow.com/users/813471/chan>*
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Lochana Menikarachchi
>>>> Senior Tech Lead
>>>> WSO2 Inc.
>>>>
>>>
>>>
>>>
>>> --
>>> Lochana Menikarachchi
>>> Senior Tech Lead
>>> WSO2 Inc.
>>>
>>
>>
>>
>> --
>> Chan (Dulitha Wijewantha)
>> Software Engineer - Mobile Development
>> WSO2 Inc
>> Lean.Enterprise.Mobileware
>> * ~Email [email protected] <[email protected]>*
>> * ~Mobile +94712112165 <%2B94712112165>*
>> * ~Website dulitha.me <http://dulitha.me>*
>> * ~Twitter @dulitharw <https://twitter.com/dulitharw>*
>> *~Github @dulichan <https://github.com/dulichan>*
>> *~SO @chan <http://stackoverflow.com/users/813471/chan>*
>>
>
>
>
> --
> Sameera Medagammaddegedara
> Software Engineer
>
> Contact:
> Email: [email protected]
> Mobile: + 94 077 255 3005
>
--
Lochana Menikarachchi
Senior Tech Lead
WSO2 Inc.
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev