繁体   English   中英

尝试自动上传文件时出现 Curl 错误 - http 没有此类文件

[英]Curl error while trying to automate file upload - http no such file

我已经搜索了各种问题,并尝试了 curl 命令的不同排列,但还没有找到一个有效的方法,所以发布这个问题,因为我可能遗漏了一些明显的东西并且看不到它。

我正在运行 curl 命令来尝试上传文件进行解析。

S-MBP:project SG$ curl -i -X POST -F "data=@/Users/SG/Desktop/project/mongodb-cluster-shard-00-02.lrqcr.mongodb.net_27017-cluster.bson.gz" 'http://localhost:3030/upload/'
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Access-Control-Allow-Headers: accept, content-type
Access-Control-Allow-Methods: POST
Access-Control-Allow-Origin: *
Date: Sat, 25 Jul 2020 14:56:05 GMT
Content-Length: 19
Content-Type: text/plain; charset=utf-8

http: no such file

根据先前的答案尝试了一些排列:

curl -i -X POST -F "filename=@/Users/SG/Desktop/project/mongodb-cluster-shard-00-02.lrqcr.mongodb.net_27017-cluster.bson.gz" http://localhost:3030/upload/

curl -i -X POST -F "filename=@mongodb-cluster-shard-00-02.lrqcr.mongodb.net_27017-cluster.bson.gz" http://localhost:3030/upload

curl -i -X POST -F filename=@/Users/SG/Desktop/project/mongodb-cluster-shard-00-02.lrqcr.mongodb.net_27017-cluster.bson.gz http://localhost:3030/upload/

curl -i -X POST -F "filename=@/Users/SG/Desktop/project/mongodb-cluster-shard-00-02.lrqcr.mongodb.net_27017-cluster.bson.gz" "http://localhost:3030/upload/"

有趣的是,如果我传入一个不存在的文件的名称,我会得到相同的错误,但如果我将目录名称更改为不存在的文件,错误是 curl(26) 让我认为命令此刻不在乎这个文件。 如果这无关紧要,我会在 Mac 上运行它,我看到一个帖子暗示 brew curl 可能存在问题。

我试图定位的表单是 docker 图像https://hub.docker.com/repository/docker/simagix/maobi的一部分

省略了一些值的表格

<form action="/upload" id="maobi" class="dropzone dz-clickable dz-started">
    <div class="dz-message">
      Drop files here or click to upload.<br>
    </div>
<div class="dz-filename"><span data-dz-name="">mongodb-cluster-shard-00-02.lrqcr.mongodb.net_27017-cluster.bson.gz</span></div></div></form>

然后我在页面中看到的脚本用于上传并解析生成 output 的文档。

    <script>
  Dropzone.options.maobi = {
    timeout: 300000,
    init: function() {
      this.on("success", function(file, responseText) {
        blob = new Blob([responseText], { type: 'text/html' }),
        anchor = document.createElement('a');
        filename = file.upload.filename;
        if ((n = filename.indexOf("mdiag-")) == 0 ) {
          n = filename.lastIndexOf(".json")
          filename = filename.substring(0, n) + ".html";
        } else if ((n = filename.lastIndexOf(".json")) > 0 ) {
        //... 
        //...
        } else if ((n = filename.indexOf(".log")) > 0 && (n = filename.lastIndexOf(".gz")) > 0) {
          filename = filename.substring(0, n) + ".html";
        } else if ((n = filename.lastIndexOf(".bson")) > 0 ) {
          filename = filename.substring(0, n) + "-cluster.html";
        }
        anchor.download = filename;
        anchor.href = (window.webkitURL || window.URL).createObjectURL(blob);
        anchor.dataset.downloadurl = ['text/html', anchor.download, anchor.href].join(':');
        anchor.click();
      });
      this.on("error", function(file, responseText) {
        alert(responseText);
      });
    }
  };
</script>

在我看来,您没有在正确的表单字段中传递文件。

从查看 Dropzone.js 文档来看,正确的字段名称似乎是file (因为这是paramName配置的默认值),而不是datafilename 但要完全确定,最好在浏览器的 devtools 中查看网络请求,看看那里使用什么 POST 字段名称来传递文件。

curl -i -X POST -F "file=@/Users/SG/Desktop/project/mongodb-cluster-shard-00-02.lrqcr.mongodb.net_27017-cluster.bson.gz" 'http://localhost:3030/upload/'

暂无
暂无

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

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