Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
supercena opened this issue Apr 26, 2024 · 10 comments
Open

Comments

@supercena
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link

marcelocecin commented Apr 27, 2024

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
Copy link
Author

@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
Copy link
Author

how to debug tagui source code?

@marcelocecin
Copy link

try using command arguments with single quotes

@supercena
Copy link
Author

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

@marcelocecin
Copy link

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
Copy link
Author

@marcelocecin thanks very much, i will try it first

@supercena
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants