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
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to