Alfresco Update File - ERROR POST

后端 未结 2 1413
说谎
说谎 2021-01-24 14:01

I\'m trying to update a file in Alfresco... And I make this code:

var csrf_header = Alfresco.util.CSRFPolicy.getHeader();
var csrf_token = Alfresco.util.CSRFPoli         


        
相关标签:
2条回答
  • 2021-01-24 14:35

    Instead of setting the header, pass the token on the url:

    if (Alfresco.util.CSRFPolicy && Alfresco.util.CSRFPolicy.isFilterEnabled())
    {
       url += "?" + Alfresco.util.CSRFPolicy.getParameter() + "=" + encodeURIComponent(Alfresco.util.CSRFPolicy.getToken());
    }
    

    As described in CSRF Policy

    When uploading a file by submitting a form with enctype multipart/form-data it is not possible to set a header on the request, the reason is not because of the enctype specifically but due to the fact that its not possible to set a header on any form submission in the browser.

    The other solution is to use Alfresco.forms.Form that takes care of everything.

    0 讨论(0)
  • 2021-01-24 14:38

    Try moving these lines inside your function:

    var csrf_header = Alfresco.util.CSRFPolicy.getHeader();
    var csrf_token = Alfresco.util.CSRFPolicy.getToken();
    

    And if that does not solve your problem and the issue turn out to be not a matter of variable scope for csrf_* vars, then you should try hint (2) from here


    UPDATE : As I explained in our chat you should replace :

    fd.append("filedata", pdfbase64);
    

    with :

    fd.append("filedata", new Blob([pdfbase64], {type: 'application/pdf'}););
    
    0 讨论(0)
提交回复
热议问题