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:
keyofcurlstatement isfiles[], notcustom_file, it is only an example ofrequestdocument here https://github.com/request/request#multipartform-data-multipart-form-uploads. So please change it tofiles[]requestalso said that the value should be astream, not a pathpathandfsto do create stream and read path fileEdited: How to write zip file from resoponse?
You want to write zip file, please reference package
JSZiphttps://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
jszipAnd this is code, please add encoding: null when request:
My file
database.mdbis 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