-
1. Re: Help!!! File content changed while uploaded via REST api
Jeff D Aug 30, 2017 10:05 PM (in response to cyu cc)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 Aug 30, 2017 11:44 PM (in response to Jeff D)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 Aug 31, 2017 2:59 AM (in response to Jeff D)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!