Giter VIP home page Giter VIP logo

Comments (20)

chriso avatar chriso commented on June 3, 2024 1

I you upgrade to 0.5.2 and then pass in the form vars like so:

var options = {
    method: 'POST',
    headers: {'content-type': 'multipart/form-data'},
    form: [
        'file=@./filepath.jpg',
        'name_discoteca=Testing',
        'id_discoteca=19',
        'ispublic=1',
        'id_user=asd'
    ],
    url: 'http://example.org/upload'
};

curl.request(options, function (err, data) {
    ....
});

It will correctly split them up as separate args to curl:

curl ... --form "file=@./filepath.jpg" --form "name_discoteca=Testing" --form "id_discoteca=19" ...

from curlrequest.

chriso avatar chriso commented on June 3, 2024

The following should work:

var curl = require('curlrequest');

var options = {
    url: 'http://example.org/upload',
    form: 'name=test&[email protected]'
};

curl(options, function (err, response) {
    // ...
});

Usually you would pass in an object for the form option such as {name: 'test', filedata: '@localfile.jpg'} but this causes the @ symbol to be escaped.

from curlrequest.

chriso avatar chriso commented on June 3, 2024

You can see the options that are passed to curl by inspecting the meta argument that is passed to the callback:

var options = {
    url: 'http://example.org/upload',
    form: '[email protected]',
    pretend: true
};

curl.request(options, function (err, data, meta) {
    console.log(meta.args);
});

The pretend option tells the lib not to make the actual request which may be useful during debugging.

from curlrequest.

hugoliv avatar hugoliv commented on June 3, 2024

Thank chriso for your answer. My question is how to manage digest auth and upload file.

This is not working:

var options = {
url: url,
form: 'image_url='+image_url,
method: 'PUT',
digest: true,
user: 'XXXXX',
password: 'xxxxxx',
verbose: true
};

nor:
var options = {
url: url,
form: 'image_url='+image_url,
method: 'PUT',
digest: {user: 'xxxx', password: 'xxxXXxxx'},
verbose: true
};

log:
URL malformed. The syntax was not correct

digest: 'xxxxx:XXXXXX' return an error:
Couldn't resolve host. The given remote host was not resolved.

from curlrequest.

hugoliv avatar hugoliv commented on June 3, 2024

if someone is interested in:
var id = 'xxxxxxx';
var psw = 'XXXXXXX';
var user = id + ':' + psw;

var options = {
url: url,
form: '[email protected]',
method: 'PUT',//case sensitive
proxy: '',// -X
digest: true,//enable digest auth
user: user,
verbose: true
};

from curlrequest.

Sk8er22 avatar Sk8er22 commented on June 3, 2024

Hi!

i need this curl
curl -X POST -H "Content-Type: multipart/form-data" -F "file=@./filepath.jpg" -F"name_discoteca=Testing" -F "id_discoteca=19" -F "ispublic=1" -F "id_user=asd" WEBURL << this works...

but i try with your library a lot of combinations using --form & --data with " ' ; & , for join all the parameters but not work

Can you explain me pls? i need POST send a file and 4 parameters

from curlrequest.

chriso avatar chriso commented on June 3, 2024

@Sk8er22 try:

var options = {
    method: 'POST',
    headers: {'Content-Type': 'multipart/form-data'},
    form: 'file=@./filepath.jpg&name_discoteca=Testing&id_discoteca=19&ispublic=1&id_user=asd'
    url: 'http://example.org/upload'
};

curl.request(options, function (err, data) {
    ....
});

from curlrequest.

Sk8er22 avatar Sk8er22 commented on June 3, 2024

nope, form with & and = with or without double quotes doesn't works :( ask for parameters

from curlrequest.

chriso avatar chriso commented on June 3, 2024

When you say doesn't work, what's actually happening? Are you getting an error, is nothing happening, or is the request being made but not with the file appended?

A few things to try:

  • try using an absolute path to your @./filepath.jpg, e.g. @/full/path/to/filepath.jpg
  • try printing out the curl args that are used (see the example here. Then try running the exact same command in the same directory as your file

from curlrequest.

Sk8er22 avatar Sk8er22 commented on June 3, 2024

When i do what you said, the php doesn't got the file but got the parameters... the only way that works is like i said with -F i add behind url comand all my -F -F -F -F this can works?

i get this printing command:

now i have this in log : curl --silent --show-error --no-buffer --url http:url.com -F "file=@/Users/user/Downloads/WiPho-master/public/previews/dscn0271.jpg" -F "name_discoteca=Testing" -F "id_discoteca=19" -F "ispublic=1" -F "id_user=ads" --request POST --location --max-redirs 3 --header Accept: / --header Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 --header Accept-Language: en-US,en;q=0.8

if i copy and paste it works! but on the JS dosen't do anything T_T

from curlrequest.

Sk8er22 avatar Sk8er22 commented on June 3, 2024

i have this error node_modules/curlrequest/index.js:223
options.header.push(key + ': ' + headers[key]);
when i use headers than u suggest,
and if i only use --data all the parameters OK but the file it's not upload

Thanks for help!!!!!!!!!!

from curlrequest.

chriso avatar chriso commented on June 3, 2024

Yeah it looks like the reason that the file isn't making it is because it's missing the Content-Type: multipart/form-data header.

What version of curlrequest are you using?

Try passing in headers: {'content-type': 'multipart/form-data'} instead.

from curlrequest.

Sk8er22 avatar Sk8er22 commented on June 3, 2024

works that header, but now i miss the parameters xD

[ '--silent',
'--show-error',
'--no-buffer',
'--url',
'http://URL',
'--data',
'id_user=123&name_discoteca=Testing&id_discoteca=19&ispublic=1&file=@/Users/user/Downloads/WiPho-master/public/previews/dscn0278.jpg',
'--request',
'POST',
'--location',
'--max-redirs',
3,
'--header',
'Accept: /',
'--header',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'--header',
'Accept-Language: en-US,en;q=0.8',
'--header',
'Content-Type: multipart/form-data',
'--user-agent',
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)' ]

And if i don't sent the headers detects the parameters but not the file... :S

File not recibed
[ '--silent',
'--show-error',
'--no-buffer',
'--url',
'http://URL',
'--data',

'id_user=123&name_discoteca=Testing&id_discoteca=19&ispublic=1&file=@/Users/user/Downloads/WiPho-master/public/previews/dscn0278.jpg',
'--request',
'POST',
'--location',
'--max-redirs',
3,
'--header',
'Accept: /',
'--header',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'--header',
'Accept-Language: en-US,en;q=0.8',
'--user-agent',
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.861.0 Safari/535.2' ]

from curlrequest.

chriso avatar chriso commented on June 3, 2024

Yeah you'll need to use form rather than data.

Try passing in an array:

form: ['file=@./filepath.jpg', 'name_discoteca=Testing', 'id_discoteca=19', 'ispublic=1', 'id_user=asd']

from curlrequest.

Sk8er22 avatar Sk8er22 commented on June 3, 2024

on curl call --form [object Object] if i set an array

and if i set everything in a line with & or ; joining them doesn't work, miss parameters... the call have to call for each object a -F ... something crazy... i don't know why

i try calling a form for each one but just write the last one, it's possible than write one for each?

from curlrequest.

chriso avatar chriso commented on June 3, 2024

Ok I've fixed the issue in version 0.5.2. Update curlrequest and then try again with passing the form vars via an array.

from curlrequest.

Sk8er22 avatar Sk8er22 commented on June 3, 2024

that's true, anyway u join the array with & and not work... just take the first parameter... --form i guess than need a --form for each one not join all parameters =/

curl --silent --show-error --no-buffer --url http://asd/asd.php --form file=@/Users/asd/Downloads/WiPho-master/public/previews/dscn0348.jpg&id_user=123&name_discoteca=Testing&id_discoteca=19&ispublic=1 --request POST --location --max-redirs 3 --header Accept: / --header Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 --header Accept-Language: en-US,en;q=0.8 --header Content-Type: multipart/form-data --user-agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_6) AppleWebKit/534.22 (KHTML, like Gecko) Chrome/11.0.683.0 Safari/534.22

from curlrequest.

Sk8er22 avatar Sk8er22 commented on June 3, 2024

I love you! i'm too tard! hahahha I owe you a beers... WORKS

from curlrequest.

chriso avatar chriso commented on June 3, 2024

Great 😄

from curlrequest.

muton avatar muton commented on June 3, 2024

@chriso Thanks for doing this library, would be handy to see the form array syntax in the readme - took me a while to track it down here!

from curlrequest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.