Thank you Senduran,
I was mistakenly put that second payload variable, (var payload =
'compName:'+compName+'file:'+csrFile;). I have already removed it.
Found that I have missed to set the enctype="multipart/form-data" attribute
in the HTML form. That's why I'm receiving 'null' value from the
request.getFile("file")".
On Tue, Apr 5, 2016 at 12:29 PM, Senduran Balasubramaniyam <
[email protected]> wrote:
> Hi Madhawa,
>
> seems like you are creating the payload variable again, but without a
> correct json format.
> Also revisit your if condition
>
> Regards
> Senduran
>
> On Tue, Apr 5, 2016 at 11:44 AM, Madhawa Perera <[email protected]> wrote:
>
>> Hi,
>>
>> I'm trying to do a simple file upload using Jaggery post() method.
>>
>> The code that I'm trying is as below,
>>
>> *HTML Form*
>>
>> <div class="form">
>> <form id="mainform" method="post" class="register-form">
>> <input type="text" name="CompanyName" placeholder="company name"/>
>> <input type="file" name="file" id="file"/>
>> <label for="file">Upload .csr file</label>
>> <input type="submit" name="upload" value="Submit">
>> </form>
>> </div>
>>
>> *Jaggery Code Snippet*
>>
>> if(request.getMethod() == "POST"){
>> var compName = request.getParameter("CompanyName");
>> var csrFile = request.getFile("file");
>> if(!compName || !csrFile){
>> response.status = 400;
>> print("<script>alert('Company Name or CSR file can not be
>> empty!');</script>");
>> } else {
>> var payload = {
>> "compName": compName,
>> "file": csrFile
>> };
>> var payload = 'compName:'+compName+'file:'+csrFile;
>> var xhr = new XMLHttpRequest();
>> var tokenEndpoint = '
>> https://172.17.0.1:8243/csrfile/1.0.0/file/upload';
>> xhr.open("POST", tokenEndpoint);
>> var authSet = "Bearer "+token;
>> xhr.setRequestHeader("Authorization", authSet);
>> xhr.setRequestHeader("Content-Type", "multipart/form-data");
>> xhr.send(payload);
>> }
>> }
>> But, "request.getFile(formFeildName)" returns 'null', even though the
>> form is submitted with a file.
>>
>> Any idea on what might help?
>>
>> Thank you
>> Best Regards,
>> Madhawa
>>
>> --
>> Madhawa Perera
>> *Software Engineer*
>> Mobile : +94 (0) 773655496
>> <%2B94%20%280%29%20773%20451194>
>> [email protected]
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> *Senduran *
> Software Engineer,
> WSO2, Inc.; http://wso2.com/ <http://wso2.com/>
> Mobile: +94 77 952 6548
>
--
Madhawa Perera
*Software Engineer*
Mobile : +94 (0) 773655496
<%2B94%20%280%29%20773%20451194>
[email protected]
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev