3 Replies Latest reply on Aug 31, 2017 2:59 AM by cyu cc

    Help!!! File content changed while uploaded via REST api

    cyu cc

      Hey guys,

           I tried to publish resource (dataresource or workbook) via REST api. It's ok with "Publishing a Resource by Using a Single Call" if the file size is smaller than 64M. But for large files, I have to process it with "Uploading the File in Parts". The POST request to initiate uploading and the PUT request to put file content in parts are successful, but finally failed to publish. The cause is that file contents has been changed during the uploading. Many bytes are changed to "[0xEF,0xBF,0xBD]". Obviously something about charset or encoding happened. According to the help document of REST api, "Note: The content being published should not be encoded (for example, using Base-64 or UTF-8).", Does tableau http server change the contents received? Anyone can help me?

        • 1. Re: Help!!! File content changed while uploaded via REST api
          Jeff D

          Hi Cyc, have you looked at a network trace (for example, with wireshark or fiddler) to see if the request is correct and the file contents are sent correctly?

          • 2. Re: Help!!! File content changed while uploaded via REST api
            cyu cc

            Hi Jeff, thank you for your reply.

            I havenot trace the transfer with fiddler, because I have never use it, and I have not too much time to learn it currently (shamed). But I have save the data been sent to local file, the data is correct.

            • 3. Re: Help!!! File content changed while uploaded via REST api
              cyu cc

              Hi Jeff, after tracing with wireshark, I've found the reason. It has nothing to do with tableau REST api.

              The cause is sending request body with following code:

               

                myreq.write("--" + boundary + "\r\nContent-Disposition: name=\"request_payload\"\r\nContent-Type: text/xml\r\n\r\n\r\n--" + boundary + "\r\nContent-Disposition: name=\"tableau_file\"; filename=\"" + fn +"\"\r\nContent-Type: application/octet-stream\r\n\r\n" + bytesRead.slice(0,n) + "\r\n--" + boundary + "--");

               

              The contents should be sent in hex mode, so I modified the code to:

               

                myreq.write("--" + boundary + "\r\nContent-Disposition: name=\"request_payload\"\r\nContent-Type: text/xml\r\n\r\n\r\n--" + boundary + "\r\nContent-Disposition: name=\"tableau_file\"; filename=\"" + fn +"\"\r\nContent-Type: application/octet-stream\r\n\r\n");

                myreq.write(bytesRead.slice(0,n), 'hex');

                myreq.write("\r\n--" + boundary + "--");

               

              Then it works ~~~

               

              Thanks again!