Announcement

Collapse
No announcement yet.

MvCALL posting a file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MvCALL posting a file

    Mivascript.com MvCALL The FILES paramiter says.

    FILES: Optional, contains variables whose values are filenames that will be uploaded to the URL specified in ACTION. The specified
    METHOD must be 'POST' or 'PUT'.

    Should exist in in the SCRIPT or DATA path?

    Can someone post an example where they posted/uploaded a file to a remote site?
    Ray Yates
    "If I have seen further, it is by standing on the shoulders of giants."
    --- Sir Isaac Newton

    #2
    Re: MvCALL posting a file

    The file path is relative to the Miva Data Directory.

    Here is an example using mvt:call, but the logic is the same for MvCALL

    Code:
    <mvt:assign name="g.filename" value="l.settings:order:id $ '.xml'" />
    <mvt:assign name="g.filepath" value="'/'" />
    <mvt:assign name="g.server_path_to_file" value="g.filepath $ g.filename" />
    
    
    <mvt:call action="'https://domain.com'" method="'POST'" files="'g.server_path_to_file'" content-type="'multipart/form-data'"></mvt:call>
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: MvCALL posting a file

      Just came across this link:
      http://www.mivascript.com/topic/file-uploading.html

      I have never used mvcall for this, only the form method, but I do have a working example of the file that sends and the file that receives it - let me know if you want to see any of that
      William Gilligan - Orange Marmalade, Inc.
      www.OrangeMarmaladeinc.com

      Comment


        #4
        Re: MvCALL posting a file

        Originally posted by Brennan View Post
        The file path is relative to the Miva Data Directory.

        Here is an example using mvt:call, but the logic is the same for MvCALL

        Code:
        <mvt:assign name="g.filename" value="l.settings:order:id $ '.xml'" />
        <mvt:assign name="g.filepath" value="'/'" />
        <mvt:assign name="g.server_path_to_file" value="g.filepath $ g.filename" />
        
        <mvt:call action="'https://domain.com'" method="'POST'" files="'g.server_path_to_file'" content-type="'multipart/form-data'"></mvt:call>
        I think the source of a lot of confusion about MvCALL is this description on MivaScript.com. This is entirely due to my incomplete understanding of the original documentation when the site was created. (Sorry to be so long winded :)

        Code:
        <MvCALL ACTION = "string: {  expression } | literal"
                METHOD = "GET|POST|HEAD|XML|RAW|OPTIONS|PUT|DELETE|TRACE|CONNECT"
                CONTENT-TYPE = "string: {  expression } | literal"
                FIELDS = "{ expression } | variable list"
                FILES = "{ expression } | literal"
                CERTFILE = "{ expression } | literal"
                CERTTYPE = "{ expression } | literal"
                CERTPASS = "{ expression } | literal"
                TIMEOUT = "{ expression } | literal"
                HEADERS = "{ expression } | literal">
        
        
                <MvCALLSTOP>
                <MvCALLCONTINUE> 
        </MvCALL>
        1. For example FIELDS = "{ expression } | variable list"
        • FIELDS: Optional, comma delimited list of variables value pairs sent to the URL when POST is used as the method.

        In every example I've seen FIELDS = "l.variable_name" this is a literal string containing a variable name NOT the literal fieldname.

        If l.variable_name contains a list if fields, it often leads users to think { l.variable_name } is the correct syntax for a variable and and "field1,field2,field3" for a list of fields. when the opposite is the case.

        Incorrect syntax is FIELDS = "{ l.variable_name} | literial fieldlist"
        Correct syntax is FIELDS = "{ 'field1,field2,field3' } | literial variable_name"

        All of the other parameters suffer the same problem; expression | literal is insufficient to describe what it expected. The parameter descriptions are equally vague.

        Brennan If you or someone else can send me the proper syntax, I will update the site. Example:

        FIELDS = "{ field list expression } | literal variable name(s)" -- comma delimited
        FILES = "{ file list expression } | literal variable name(s)" -- comma delimited

        One other thing: are fields expected to be global variables? If so should they be specified with or without the prefix g.
        e.g. "{ 'field1,field2,field3' }" OR "{ 'g.field1,g.field2,g.field3' }"
        Last edited by RayYates; 12-18-15, 09:32 AM.
        Ray Yates
        "If I have seen further, it is by standing on the shoulders of giants."
        --- Sir Isaac Newton

        Comment


          #5
          Re: MvCALL posting a file

          Something not quite right with my script. The fields are received but not the file.

          Here's the original php version.
          Code:
          $post = array('state' => 'csvorder',
              'client' => 'shoecare',
              'recipient' => '[email protected]',
              'low_notice_email' => '[email protected]',
              'subject' => ' Fulfillment Order',
              'dont_send_orderer' => 1,
              'csvfile' => '@' . $filelocation);
              
              curl_setopt($curlClient, CURLOPT_URL, 'http://warehouse.somedomain.com/cgi-bin/process_inv_order.cgi');
              curl_setopt($curlClient, CURLOPT_RETURNTRANSFER, 1);
              curl_setopt($curlClient, CURLOPT_POST, 1);
              curl_setopt($curlClient, CURLOPT_POSTFIELDS, $post);
              curl_setopt($curlClient, CURLOPT_SSL_VERIFYPEER, 0);
              curl_setopt($curlClient, CURLOPT_SSL_VERIFYHOST, 0);
              $result = curl_exec($curlClient);

          Here's what I'm doing.
          Code:
          <mvt:assign name="g.state" value="'csvorder'" />
          <mvt:assign name="g.client" value="'clientname'" />
          <mvt:assign name="g.recipient" value="'[email protected]'" />
          <mvt:assign name="g.low_notice_email" value="'[email protected]'" />
          <mvt:assign name="g.subject" value="g.customer $ ' Fulfillment Order'" />
          <mvt:assign name="g.dont_send_orderer" value="1" />
          <mvt:assign name="g.csvfile" value="g.pacFile" />
          
          <mvt:assign  name="g.FieldList"  value="'g.state,g.client,g.recipient,g.low_notice_email,g.subject,g.dont_send_orderer,g.csvfile'"  />
          
          <mvt:item name="ry_toolbelt"  param="do|'/mm5/post_fulfillment.mvc'|g.http_responce|Post_Fulfillment_Upload(g.DebugPacful,  g.PacfulUrl, g.FieldList, g.pacFile, g.response)" />
          The call function:
          Code:
          <MvFUNCTION NAME="Post_Fulfillment_Upload" PARAMETERS="debug, url, fieldlist, filepath, response var">
              <MvIF EXPR="{ l.debug }">
                  <MvEVAL EXPR="{ '<hr>Post_Fulfillment_Upload()<br>' }">
                  <MvEVAL EXPR="{ 'l.url = ' $ l.url $ ' <br>' }">
                  <MvEVAL EXPR="{ 'l.fieldlist = ' $ l.fieldlist $ ' <br>' }">
                  <MvEVAL EXPR="{ 'l.filepath = ' $ l.filepath $ ' <hr>' }">
              </MvIF>
          
              <MIVA MvCALL_Error = "nonfatal, nodisplay">
          
              <MvCAPTURE VARIABLE = "l.response">
                  <MvCALL ACTION = "{ l.url }"
                      METHOD = "POST"
                      CONTENT-TYPE="multipart/form-data"
                      FIELDS = "{ l.fieldlist }"
                      FILES = "l.filepath">
          
                      <MvASSIGN NAME = "l.http_response" VALUE = "{ s.callreturnheader[ 1 ] }">
                      <MvEVAL EXPR = "{ s.callvalue }">
                  </MvCALL>
              </MvCAPTURE>
          
              <MvIF EXPR="{ g.MvCALL_Error }">
                  <MvEVAL EXPR="{ 'g.MvCALL_Error = ' $ l.http_response  $ ' -- ' $ g.MvCALL_Error $ ' <br>' }">
              </MvIF>
          
              <MvFUNCTIONRETURN VALUE="{ l.http_response }">
          </MvFUNCTION>
          Ray Yates
          "If I have seen further, it is by standing on the shoulders of giants."
          --- Sir Isaac Newton

          Comment


            #6
            Re: MvCALL posting a file

            What is the file path you are sending? It should be in the MivaData folder and the path relative to that.
            Brennan Heyde
            VP Product
            Miva, Inc.
            [email protected]
            https://www.miva.com

            Comment


              #7
              Re: MvCALL posting a file

              Yes, the file is created in the /mivadata folder. The client says the file he receives is empty but I've confirmed the contents are not empty.
              Ray Yates
              "If I have seen further, it is by standing on the shoulders of giants."
              --- Sir Isaac Newton

              Comment

              Working...
              X