Comments (20)
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.
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.
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.
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.
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.
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.
@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.
nope, form with & and = with or without double quotes doesn't works :( ask for parameters
from curlrequest.
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.
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.
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.
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.
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.
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.
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.
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.
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.
I love you! i'm too tard! hahahha I owe you a beers... WORKS
from curlrequest.
Great 😄
from curlrequest.
@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)
- curl_path
- --request "VERB" is insufficient for certain HTTP methods (head) HOT 1
- How can I use proxy HOT 1
- No data returned when remote file exceeds certain size HOT 1
- Downloading a file
- options.curl_path not implemented
- request return with 400 "bad request" HOT 1
- How can i able to "sets content type to application/json and sends request body as JSON string, instead of a query string" ?
- Downloading ascii vs binary files? HOT 1
- How do you use the process option?
- Uncaught Error: spawn curl ENOENT at exports._errnoException
- upload file usinng username pass
- Error when sending lots of data in body HOT 1
- Provide response code
- spawn curl ENOENT AWS Lambda HOT 1
- Security Notice & Bug Bounty - Command Injection - huntr.dev HOT 1
- Security Notice & Bug Bounty - Arbitrary File Read - huntr.dev HOT 2
- interface option
- getting error Uncaught (in promise) TypeError: Cannot read property 'apply' of undefined HOT 1
- Security Issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from curlrequest.