2

Good day,

I've spent some time trying to upload file to ipfs using http request (from meteor).

Meteor.startup(() => {
  // code to run on server at startup
        Meteor.methods({
                "getFile": function(){
                        var results = HTTP.get('http://127.0.0.1:5001/api/v0/object/get', {timeout:5000, params:
                        {"arg": "QmcNHzJeDphzamLVgKq1R3wmFXqw8EbWLVS6qhAPGohobM",
                        "encoding": "json"}});
                        return (results)
                },
                "uploadFile": function(){
                        var results = HTTP.post("http://127.0.0.1:5001/api/v0/add", {timeout:5000, params:{
                        "path": "/home/shultzi/trial.txt",
                        "stream-channels": "true",
                        "arg": "/home/shultzi/trial.txt",
                        //"Content-Type": "multipart/mixed",
                        //"file": "trial.txt"
                        //"Content-Type": "multipart/form-data"

                        }, header: {
                        //"Content-Type": "application/octet-stream",
                        "enctype": "multipart/form-data",
                        "Content-Type": "multipart/form-data",
                        }});
                    return (results)
            }

    })
})

The first http request (getFile) works just fine, but when I'm trying to upload the file I constantly get the error message

"File argument 'path' is required"

. I've tried to modify my http request in many ways, adding stream-channels and changing multipart, but nothing seems to work.

I know there're some js apis out there, but I really want to work with my own http requests.

I'll highly appreciate any type of help, suggestion or insight you might have!

0

I'm not sure that this will help or not, but I was able to get the upload working through Postman. The curl looks like this...

    curl -X POST \
  http://localhost:5001/api/v0/add \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F image=@/Users/$user/Desktop/cat.jpg

I also had problems with the file path argument and the answer is most definitely not pass in a param with 'path' to your file. If I get it working on Meteor I will paste it back in here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.