繁体   English   中英

关于 curl 命令中的文件上传参数

[英]Regarding file upload parameter in curl command

I'm trying to run a curl command in azure devops bash script task, where I'm trying to upload a jar from artifact path.

在 curl 命令中给出 static 文件路径时,我能够成功运行它,但是我们如何动态传递文件路径?

curl -X POST \
https://anypoint.mulesoft.com/cloudhub/api/v2/applications \
-H 'authorization: bearer <your_token>' \
-H 'x-anypnt-env-id: <your_env_id>' \
-H 'x-anypnt-org-id: <your_org_id>' \
-F 'appInfoJson={
"domain": "<yourapplicationName>",
"muleVersion" : {"version":"3.9.1"},
"region" : "us-east-1", 
"monitoringEnabled":true,
"monitoringAutoRestart" : true,
"workers": {"amount":1, "type": {"name":"Micro","weight":"0.1","cpu":"0.1 vCores", "memory":"500 MB memory"}},
"loggingNgEnabled":true,
"persistentQueues":false,
 "properties":{
      "key1":"value1"
   }
}' \
-F autoStart=true \
-F file=@/path_to_the_file/yourapplication.jar

有没有办法动态地给出文件路径? 我试图给这种方式-F file=@/path_to_the_file/**.jar**不被接受。

尝试在变量中使用文件名,如下所示。 注意变量周围的 {}。 确保您的 ls 命令仅返回 1 个文件。 对于多个文件,使用多个 -F arguments。

样本测试数据:

$ ls *.jar
b.jar
$ echo $(ls -R ${PWD}/*.jar)
/root/b.jar

上面的命令生成文件的绝对路径

-F file=@$(ls -R ${PWD}/*.jar)

${PWD} 打印当前工作目录的路径并帮助创建相关文件的绝对路径。

另外,如果要附加多个文件,请使用多个 -F arguments

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM