Skip to content

Commit 437849b

Browse files
committed
adding csv api
1 parent 5c15b54 commit 437849b

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

lib/dispatchRequest.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function btoaImplementation(str) {
2424
* @param {Object} payload data to be transmitted to endpoint
2525
* @param {String} key optional basic auth string to be passed
2626
*/
27-
function DispatchRequest(url, action, payload, local_auth, remote_auth = null, files) {
27+
function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
2828
/*
2929
*CORS is only required when trying to fetch data from a browser,
3030
*as browsers by default will block requests to different origins
@@ -91,13 +91,8 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, f
9191
case CONST.ADD_CSV:
9292
options.headers = options.headers ? options.headers : {}
9393
options.headers['Content-Type'] = 'multipart/form-data'
94-
const formData = new FormData();
95-
files.map((item)=>{
96-
formData.append(item.name, item.file)
97-
})
98-
formData.append('payload', payload)
9994
return axiosInstance
100-
.put(url, formData, options)
95+
.put(url, payload, options)
10196
.then(response => response.data)
10297
.catch(err => {
10398
const e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err))

lib/woqlClient.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,8 @@ WOQLClient.prototype.insertTriples = function(gtype, gid, turtle, commit_msg) {
393393
)
394394
}
395395

396-
397396
/**
398-
* Appends the passed turtle to the contents of a graph
397+
* Adds a csv
399398
*
400399
* @param {string} gtype type of graph |instance|schema|inference|
401400
* @param {string} gid TerminusDB Graph ID to update, main is the default value
@@ -404,22 +403,22 @@ WOQLClient.prototype.insertTriples = function(gtype, gid, turtle, commit_msg) {
404403
* @return {Promise}
405404
*/
406405

407-
//DispatchRequest(url, action, payload, local_auth, remote_auth = null, files) {
408406
WOQLClient.prototype.addCSV = function(gtype, gid, csv, commit_msg) {
409407
if (commit_msg && csv) {
410408
let commit = this.generateCommitInfo(commit_msg)
409+
const formData = new FormData();
410+
for(var x = 0; x<csv.length; x++) {
411+
formData.append('file', csv[x])
412+
}
413+
formData.append('payload', JSON.stringify(commit))
411414
return this.dispatch(
412415
CONST.ADD_CSV,
413-
this.connectionConfig.dbURL(),
414-
commit,
415-
files=csv
416+
this.connectionConfig.csvURL(),
417+
formData,
416418
)
417419
}
418420
}
419421

420-
421-
422-
423422
/**
424423
* Executes a WOQL query on the specified database and returns the results
425424
*

0 commit comments

Comments
 (0)