aisingapore / TagUI

Free RPA tool by AI Singapore
Apache License 2.0
5.45k stars 572 forks source link

how to use tagui using api directive to post a flie to Remote machine #1374

Closed supercena closed 4 weeks ago

supercena commented 2 months ago

api_config = {method:'POST', header:['Content-type: multipart/form-data'], body:'name=sd&file=@C:\Users\Admin\AppData\Local\Postman\app-6.0.10\ffmpeg.dll'}; api http://localhost:8080/File/ echo api_result

supercena commented 2 months ago

error:

{"timestamp":"2024-04-26T01:25:49.657+0000","status":500,"error":"Internal Server Error","message":"Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found","path":"/File/"}

supercena commented 2 months ago

and i have another question if i use python script to send a Chinese path file to Remote machine in tagui script , that is not ok.

marcelocecin commented 2 months ago

try to use run command with curl

Runs a command in Command Prompt or Terminal and saves the stdout to the variable run_result.

run [shell command] Examples

run cmd /c mkdir new_directory

supercena commented 2 months ago

@marcelocecin hello i use curl command on windows by tagui script as follows:

run cmd /c D:\curl-8.7.1_7-win64-mingw\curl-8.7.1_7-win64-mingw\bin\curl.exe -X POST -F "file=@D:\rpa\rpademo\tuijian\1714300843597.txt" http://localhost:8080/File/ echo run_result

errors: The filename, directory name, or volume label syntax is incorrect.

but I use curl -X POST -F "file=@D:\rpa\rpademo\tuijian\1714300843597.txt" http://localhost:8080/File/ on cmd command ,that is ok. but using tagui ,error is The filename, directory name, or volume label syntax is incorrect. why?

supercena commented 2 months ago

how to debug tagui source code?

marcelocecin commented 2 months ago

try using command arguments with single quotes

supercena commented 2 months ago

@marcelocecin using single quotes is not ok . it is too hard to use.

marcelocecin commented 2 months ago

so try to create tagui_local.js

example:

function send_attachment_url(msg,file,url) {
  casper.options.waitTimeout = (30*1000);
  casper.waitForExec('curl -F msg="'+msg+'" -F upload=@'+file+' '+url, null, function(response) {
  run_result = '';
  run_result = (response.data.stdout.trim() || response.data.stderr.trim()); run_result = run_result.replace(/\r\n/g,'\n');
  run_json = response.data;
  this.exit();},
  function() {this.echo('ERROR - command to run exceeded '+(casper.options.waitTimeout/1000).toFixed(1)+'s timeout').exit();});
}

then in your script.tag

https://google.com
wait 5
js send_attachment_url("sd","C:\Users\Admin\AppData\Local\Postman\app-6.0.10\ffmpeg.dll","http://localhost:8080/File/")

PS: If it still doesn't work, I suggest testing sending it to an external url, for example https://webhook.site/

supercena commented 2 months ago

@marcelocecin thanks very much, i will try it first

supercena commented 1 month ago

I optimize and refine the syntax of my code. Here's the updated version and it works on windows. @marcelocecin thanks so much

js begin function send_attachment_url() { var fs = require('fs'); // Import the file system module var dataFilePath = 'D:\rpa\rpademo\xinniuren\历史.txt'; if (!fs.exists(dataFilePath)) { casper.echo('File does not exist: ' + dataFilePath).exit(); } if (!fs.isFile(dataFilePath)) { casper.echo('Path is not a file: ' + dataFilePath).exit(); } if (!fs.isReadable(dataFilePath)) { casper.echo('File is not readable: ' + dataFilePath).exit(); } var curlPath = 'D:/curl-8.7.1_7-win64-mingw/curl-8.7.1_7-win64-mingw/bin/curl.exe'; casper.start().waitForExec(curlPath, ["-X", "POST", "-F", "file=@" + dataFilePath.replace(/\/g, '/'), "http://localhost:8080/File/"], function(response) { this.echo(JSON.stringify(response.data)); }, function() { this.echo('Command timed out'); }, 20000); casper.run(function() { this.exit(); }); } send_attachment_url(); js finish