[looping Ruchira]

On Fri, Apr 24, 2015 at 10:44 AM, Supun Sethunga <[email protected]> wrote:

> Hi Malith,
>
> It gives the same result.
>
> Thanks,
> Supun
>
> On Fri, Apr 24, 2015 at 10:41 AM, Malith Munasinghe <[email protected]>
> wrote:
>
>> Links for the above
>>
>> [1]
>> http://stackoverflow.com/questions/10801122/handling-multipart-attachments-in-cxf-apis
>>
>>
>> On Fri, Apr 24, 2015 at 10:40 AM, Malith Munasinghe <[email protected]>
>> wrote:
>>
>>> Hi Supun,
>>>
>>> As discussed in [1] for CXF 2.6.x api file uploading using multipart
>>> content type can be done using Attachement Argument type instead of
>>> InputStream. Can you try using
>>>
>>> @Multipart(value = "file") @NotNull Attachment attachment
>>> Then use
>>>
>>> InputStream inputStream = attcehment.getObject(InputStream.class);
>>>
>>> to get the InputStream.
>>>
>>> Thank you,
>>> Regards
>>>
>>>
>>> On Fri, Apr 24, 2015 at 9:26 AM, Supun Sethunga <[email protected]> wrote:
>>>
>>>> Hi Malith,
>>>>
>>>> Using the latest Chrome/Firefox versions. This isn't working when
>>>> called from a java-client either.
>>>>
>>>> Catch here is, rest of the form data get submitted correctly. AFAIU
>>>> problem is in the way the file is streamed to the server (the way it gets
>>>> attached to the request).
>>>>
>>>> Thanks,
>>>> Supun
>>>>
>>>> On Fri, Apr 24, 2015 at 9:14 AM, Malith Munasinghe <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Supun,
>>>>>
>>>>> Can you check the browser version of yours ? As of [1] FormData
>>>>> emulation for older browser (Below Safari 5 / Firefox 4) you might have to
>>>>> change it to the way mentioned in top Ranked answer.
>>>>>
>>>>> [1]
>>>>> http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax
>>>>>
>>>>> On Fri, Apr 24, 2015 at 9:02 AM, Supun Sethunga <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi Malith/Thilini,
>>>>>>
>>>>>> Thanks for the suggestion. I had tried that. Didn't work :/
>>>>>>
>>>>>> Regards,
>>>>>> Supun
>>>>>>
>>>>>> On Fri, Apr 24, 2015 at 8:45 AM, Thilini Cooray <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi Supun,
>>>>>>>
>>>>>>> [1] also suggests to make contentType false.
>>>>>>>
>>>>>>> [1]
>>>>>>> http://stackoverflow.com/questions/12831680/jquery-ajax-multipart-form-data-not-sending-data
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>> On Fri, Apr 24, 2015 at 8:44 AM, Malith Munasinghe <[email protected]
>>>>>>> > wrote:
>>>>>>>
>>>>>>>> Hi Supun!
>>>>>>>>
>>>>>>>> Try Making contentType: false,
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Malith.
>>>>>>>>
>>>>>>>> On Thu, Apr 23, 2015 at 5:20 PM, Supun Sethunga <[email protected]>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> Requirement was to let a user upload a data file from a UI
>>>>>>>>> (html/jaggery), and the backend which handles file uploading is 
>>>>>>>>> exposed as
>>>>>>>>> a REST service. Backend service method I wrote looks as follows:
>>>>>>>>>
>>>>>>>>>     @POST
>>>>>>>>>>     @Produces(MediaType.APPLICATION_JSON)
>>>>>>>>>>     @Consumes(MediaType.MULTIPART_FORM_DATA)
>>>>>>>>>>     public Response uploadDataset(@Multipart("datasetName")
>>>>>>>>>> String datasetName,
>>>>>>>>>>                                   @Multipart("version") String
>>>>>>>>>> version,
>>>>>>>>>>                                   @Multipart("description")
>>>>>>>>>> String description,
>>>>>>>>>>                                   @Multipart("sourceType") String
>>>>>>>>>> sourceType,
>>>>>>>>>>                                   @Multipart("destination")
>>>>>>>>>> String destination,
>>>>>>>>>>                                   @Multipart("sourcePath") String
>>>>>>>>>> sourcePath,
>>>>>>>>>>                                   @Multipart("dataFormat") String
>>>>>>>>>> dataFormat,
>>>>>>>>>>                                   @Multipart("file") InputStream
>>>>>>>>>> inputStream) {
>>>>>>>>>>         . . .
>>>>>>>>>>         . . .
>>>>>>>>>>     }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> The InputStream is then written to a file at the server side. This
>>>>>>>>> method works fine when I call this with CURL using:
>>>>>>>>>
>>>>>>>>> *curl -X POST -b cookies  http://localhost:9763/api/datasets
>>>>>>>>>> <http://localhost:9763/api/datasets> -H "Authorization: Basic
>>>>>>>>>> YWRtaW46YWRtaW4=" -H "Content-Type: multipart/form-data" --form
>>>>>>>>>> datasetName=TestDataset --form version=1.0.0 --form
>>>>>>>>>> description=TestDescription --form sourceType=file --form 
>>>>>>>>>> destination=file
>>>>>>>>>> --form dataFormat=CSV --form
>>>>>>>>>> file=@/home/supun/Supun/MachineLearning/data/IndiansDiabetes.csv 
>>>>>>>>>> --form
>>>>>>>>>> sourcePath=/temp*
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Also works fine when I used Chrome's REST client.
>>>>>>>>>
>>>>>>>>> However,  when I call the same service, using AJAX, the file is
>>>>>>>>> written with empty content. Follow is the sample snippet.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> *var formData = new FormData();*
>>>>>>>>>> *  formData.append("file", fileInput[0]['files'][0],
>>>>>>>>>> 'IndiansDiabetes.csv');*
>>>>>>>>>> * formData.append("datasetName", name);*
>>>>>>>>>> * formData.append("version", version);*
>>>>>>>>>> * formData.append("description", comments);*
>>>>>>>>>> * formData.append("sourceType", dataSourceType);*
>>>>>>>>>> * formData.append("sourcePath", null);*
>>>>>>>>>> * formData.append("destination", dataTargetType);**
>>>>>>>>>> formData.append("dataFormat", dataType);*
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> *       var baseUrl = getBaseUrl(window.location.href);*
>>>>>>>>>> *       $.ajax({*
>>>>>>>>>> *           type: 'POST',*
>>>>>>>>>> *           url: baseUrl + '/api/datasets', *
>>>>>>>>>> *           contentType: "multipart/form-data",*
>>>>>>>>>> *    processData: false,*
>>>>>>>>>> *           data: formData,**           beforeSend :
>>>>>>>>>> function(xhr) {*
>>>>>>>>>>
>>>>>>>>>> *                xhr.setRequestHeader("Authorization", "Basic " +
>>>>>>>>>> "YWRtaW46YWRtaW4=");*
>>>>>>>>>> *            },*
>>>>>>>>>> *            success : function(res){*
>>>>>>>>>> *           console.log('success');*
>>>>>>>>>> *            },*
>>>>>>>>>> *            error :  function(res){*
>>>>>>>>>> *           console.log('failed');*
>>>>>>>>>> *            }   *
>>>>>>>>>> *        });** })*
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> One thing I noticed was, When calling the service using CURL and
>>>>>>>>> REST-Client, the *@Multipart("file") InputStream inputStream*
>>>>>>>>> binds to a "LoadingByteArrayOutputStream", but when calling from AJAX 
>>>>>>>>> (or
>>>>>>>>> even with a java client) it binds to a
>>>>>>>>> "org.apache.cxf.attachment.DelegatingInputStream", and hence writing 
>>>>>>>>> an
>>>>>>>>> empty content to the server.
>>>>>>>>>
>>>>>>>>> Any idea on how to overcome this?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Supun
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> *Supun Sethunga*
>>>>>>>>> Software Engineer
>>>>>>>>> WSO2, Inc.
>>>>>>>>> http://wso2.com/
>>>>>>>>> lean | enterprise | middleware
>>>>>>>>> Mobile : +94 716546324
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Dev mailing list
>>>>>>>>> [email protected]
>>>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Malith Munasinghe | Software Engineer
>>>>>>>> M: +94 (071) 9401122
>>>>>>>> E: [email protected]
>>>>>>>> W: http://wso2.com
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> Dev mailing list
>>>>>>>> [email protected]
>>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Best Regards,
>>>>>>>
>>>>>>> *Thilini Cooray*
>>>>>>> Software Engineer
>>>>>>> Mobile : +94 (0) 774 570 112 <%2B94%20%280%29%20773%20451194>
>>>>>>> E-mail : [email protected]
>>>>>>>
>>>>>>> WSO2 Inc. www.wso2.com
>>>>>>> lean.enterprise.middleware
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> *Supun Sethunga*
>>>>>> Software Engineer
>>>>>> WSO2, Inc.
>>>>>> http://wso2.com/
>>>>>> lean | enterprise | middleware
>>>>>> Mobile : +94 716546324
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Malith Munasinghe | Software Engineer
>>>>> M: +94 (071) 9401122
>>>>> E: [email protected]
>>>>> W: http://wso2.com
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> *Supun Sethunga*
>>>> Software Engineer
>>>> WSO2, Inc.
>>>> http://wso2.com/
>>>> lean | enterprise | middleware
>>>> Mobile : +94 716546324
>>>>
>>>
>>>
>>>
>>> --
>>> Malith Munasinghe | Software Engineer
>>> M: +94 (071) 9401122
>>> E: [email protected]
>>> W: http://wso2.com
>>>
>>
>>
>>
>> --
>> Malith Munasinghe | Software Engineer
>> M: +94 (071) 9401122
>> E: [email protected]
>> W: http://wso2.com
>>
>
>
>
> --
> *Supun Sethunga*
> Software Engineer
> WSO2, Inc.
> http://wso2.com/
> lean | enterprise | middleware
> Mobile : +94 716546324
>



-- 
*Supun Sethunga*
Software Engineer
WSO2, Inc.
http://wso2.com/
lean | enterprise | middleware
Mobile : +94 716546324
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to