【问题标题】:Curl error while trying to automate file upload - http no such file尝试自动上传文件时出现卷曲错误 - http 没有这样的文件
【发布时间】:2020-07-25 15:18:23
【问题描述】:

我已经搜索了各种问题,并尝试了 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>

然后是我在页面中看到的脚本,我认为该脚本用于上传并解析生成输出的文档。

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

【问题讨论】:

    标签: mongodb docker curl


    【解决方案1】:

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

    通过查看 Dropzone.js 文档,正确的字段名称似乎是 file(因为这是 paramName configuration 的默认值),而不是 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/'
    

    【讨论】:

    • 不会撒谎,现在正在发生重要的捂脸时刻。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多