I am trying to convert the following curl to node request.
curl -F files[][email protected] 'https://www.rebasedata.com/api/v1/convert?outputFormat=mysql&errorResponse=zip' -o output.zip
I have tried using request or node-libcurl but can't find a way to upload a mdb file.
The code I have is
var request = require('request');
var options = {
url: 'https://www.rebasedata.com/api/v1/convert?outputFormat=mysql&errorResponse=zip',
method: 'POST',
formData: {
custom_file: {
options: {
contentType: 'application/mdb'
},
value: path.resolve(__dirname, 'myMdb.mdb')
}
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
But I kept getting error like no files given or couldn't open file.
Any help is appreciated.
You have some errors:
key
ofcurl
statement isfiles[]
, notcustom_file
, it is only an example ofrequest
document here https://github.com/request/request#multipartform-data-multipart-form-uploads. So please change it tofiles[]
request
also said that the value should be astream
, not a pathpath
andfs
to do create stream and read path fileEdited: How to write zip file from resoponse?
You want to write zip file, please reference package
JSZip
https://stuk.github.io/jszip/documentation/howto/read_zip.html. After havebody
, read zip and write to zip file.I've done your problem with new code, the callback handler is from document of
request
, you can ignore my callback handler.Updated zip file
Before please install package
jszip
And this is code, please add encoding: null when request:
My file
database.mdb
is uploaded here https://ufile.io/prnsi (file will be deleted after 30 days from the answer posted).And when
console.log(zip.files);
, you'll receive from my database file