简体   繁体   中英

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

I've searched through the various questions and tried different permutations of curl commands but yet to find one the works so posting the question as I'm likely missing something obvious and cannot see it for looking.

I'm running a curl command to try and upload a file for parsing.

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

Some of the permutations tried based on previous answers:

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

Interestingly, if I pass in the name of a file that doesn't exist I get the same error but if I change the name of the directory to one that doesn't exist the error is a curl(26) making me think that the command couldn't care less about the file at the moment. I am running this on a mac if that's of nay relevance, I saw a post that implied there may be an issue with brew curl.

The form that I'm trying to target is part of the docker image https://hub.docker.com/repository/docker/simagix/maobi

The form with some values omitted

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

and then the script I see in the page that I believe is used to upload and then parse the document generating the 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>

It seems to me that you are not passing the file in the right form field.

From looking at the Dropzone.js documentation, it seems the right field name is file (since that's the default for the paramName configuration ), not data or filename . But to be entirely sure, it'd be best to look at the network request in your browser's devtools and see what POST field name is used there for passing the file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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