I'm trying to do a bulkInsert but I keep getting a 400 error message:
{code: "VALIDATION", message: "Invalid parameters"}
Here is my code:
import React, { Component } from 'react';
class App extends Component {
constructor(props) {
super(props);
this.testFn = this.testFn.bind(this);
}
testFn() {
const data = [{name:"John Doe", tel:"555-111-1111"},{name:"John Doe", tel:"555-222-2222"}];
buildfire.publicData.bulkInsert(data, 'testTag', function(err, res) {
if (err) {
console.log("ERROR", err);
} else {
console.log("SUCCESSFULLY BULK INSERTED", res);
}
});
}
render() {
return (
<div>
<button onClick={this.testFn}>Test Insert</button>
</div>
);
}
}
export default App;
If I change buildfire.publicData.bulkInsert to buildfire.publicData.insert the call is successful and I can find my array in res.data but I want each object to create it's own record. The example data I am trying to save is coming straight from the docs.
I had been able to reproduce the issue that you described, although it seems to no longer be a problem. Perhaps it was a temporary glitch, or something was changed in the system recently.
I'd suggest trying again, as it appears to be working fine now.
Related
I set up a website that basically uses Nodejs to fetch the image and after that sends it to ejs to display on the page, what happens is that sometimes the image appears and sometimes it looks like the website loads before the image can be loaded by the node.
I left the two ways I tried, one commented and the other that was the last one I tried.
This is app.js
function retornaImagens(id){
let imagens= {
assPacUrl: ''
}
/*
if (fs.existsSync(`${__dirname}\\arquivos\\consultas\\${id}\\assPac.png`)) {
fs.readFile(
`${__dirname}\\arquivos\\consultas\\${id}\\assPac.png`, 'base64',
(err, base64Image) => {
if (err) {
console.log(err)
} else {
imagens.assPacUrl = `data:image/png;base64, ${base64Image}`
}
}
)
}
*/
fs.access(`${__dirname}\\arquivos\\consultas\\${id}\\assPac.png`,(err)=>{
if(err){}else{
fs.readFile(
`${__dirname}\\arquivos\\consultas\\${id}\\assPac.png`, 'base64',
(err, base64Image) => {
if (err) {
console.log(err)
} else {
imagens.assPacUrl = `data:image/png;base64, ${base64Image}`
}
}
)
}
})
return imagens;
}
app.get('/consultas/:id/termo',(req,res)=>{
var imagens = retornaImagens(req.params.id);
Consulta.findOne({link:`/consultas/${req.params.id}/login`}).populate('medico paciente').exec((err,consulta)=>{
if(err){
console.log(err)
}else{
console.log(imagens)
res.render('consulta/termo',{consulta:consulta,id:req.params.id,imagens})
}
})
})
This is the ejs file
<img src="<%= imagens.assPacUrl %>">
If you have tips to make the code cleaner and consume less memory, please send me.
The problem was in the loading time, it was taking longer to load the image so the program continued and rendered the website empty, adding a settimeOut.
function enviaTermo(data){
Consulta.findOne({link:data.link}).populate('medico paciente').exec((err, consulta) => {
if (err) {
console.log(err)
} else {
console.log(imagens)
io.to(consulta._id).emit('termo', { consulta: consulta, imagens: imagens })
}
})
}
setTimeout(() => {
enviaTermo(data)
}, 450);
Update: At the moment I'm looking at updating ScriptPath and Option
I have a working python script and would like to call it from a React Component
I tired following the direction from python-shell documentation the best I could.
The exact error I get is provided as a screenshot below.
Is there a more efficent way to do this ?
import React, { Component } from "react";
import { PythonShell } from "python-shell";
class RunPy extends Component {
runPy() {
console.log("Im here");
PythonShell.run("../Py/py.py", null, function(err) {
if (err) throw err;
console.log("finished");
});
}
render() {
return (
<button type="button" onClick={this.runPy}>
RunPy
</button>
);
}
}
export default RunPy;
React Error
I am running a Express application with Node in the backend. I have 2 functions in a component in NodeJS which I am trying to access from my service. The link for both are the same in the service. It is able to connect one of the functions from the service.
However, it is showing 404 not found for accessing the second function in the same component.
Has anyone faced any such issue and if so how can it be rectified?
EDITED :
Some code for reference :
component1.component.ts
getallprojectcat()
{
this.authenticationService.getprojectcat()
.pipe(first())
.subscribe(
data => {
this.data = data;
},
error => {
this.loading = false;
});
}
}
component2.component.ts
showprojects(moid)
{
this.authenticationService.getprojectslist(moid)
.pipe(first())
.subscribe(
data => {
this.silver = data;
},
error => {
console.log('some error');
this.alertService.error(error);
this.loading = false;
});
}
the .service file
getprojectcat()
{
return this.http.get<any>(this.studenturl+'/getprojectcata/')
.pipe(map(allprojectcat => {
console.log(JSON.stringify(allprojectcat));
return allprojectcat;
}));
}
getprojectslist(moid)
{
return this.http.get(this.studenturl+'/getprojects/'+moid)
.pipe(map(projectslist => {
console.log("Projects List:"+JSON.stringify(projectslist));
return projectslist;
})).catch(this.handleError);
}
Backend .js file
exports.getprojectcata = function(req, res){
console.log("First Function");
};
exports.getprojects = function(req, res){
console.log("Second Function");
};
The function getprojectcata is working in the first component. However, it shows an 404 not found on the getprojects function in the second component. I have checked the following things -
Routing does not seem to be the problem as it is moving to the next component without any issues.
We have also tried calling the getprojectscata through the same service in component and it worked.
I am new to Apostrophe and trying to create a contact us form with file attachment in Apostrophe by following the tutorial.
https://apostrophecms.org/docs/tutorials/intermediate/forms.html
I have also created the attachment field in my index.js and it works fine from the admin panel.
Now, I am trying to create my own html for the form with file submission.
// in lib/modules/contact-form-widgets/public/js/always.js
apos.define('contact-form-widgets', {
extend: 'apostrophe-widgets',
construct: function(self, options) {
self.play = function($widget, data, options) {
var $form = $widget.find('[data-contact-form]');
var schema = self.options.submitSchema;
var piece = _.cloneDeep(self.options.piece);
return apos.schemas.populate($form, self.schema, self.piece, function(err) {
if (err) {
alert('A problem occurred setting up the contact form.');
return;
}
enableSubmit();
});
function enableSubmit() {
$form.on('submit', function() {
submit();
//I can access file here
// console.log($form.find('file'))
return false;
});
}
function submit() {
return async.series([
convert,
submitToServer
], function(err) {
if (err) {
alert('Something was not right. Please review your submission.');
} else {
// Replace the form with its formerly hidden thank you message
$form.replaceWith($form.find('[data-thank-you]'));
}
});
function convert(callback) {
return apos.schemas.convert($form, schema, piece, callback);
}
function submitToServer(callback) {
return self.api('submit', piece, function(data) {
alert("I AM AT SUBMIT API ")
if (data.status === 'ok') {
// All is well
return callback(null);
}
// API-level error
return callback('error');
}, function(err) {
// Transport-level error
alert("I AM HERE AT API ERROR")
return callback(err);
});
}
}
};
}
});
//and my widget.html is
<div class="form-group">
<input name="custom-file" type="file">
</div>
When I run this I get following errors
user.js:310 Uncaught TypeError: Cannot read property 'serialize' of undefined
at Object.self.getArea (user.js:310)
at Object.self.getSingleton (user.js:303)
at Object.convert (user.js:686)
at user.js:164
at async.js:181
at iterate (async.js:262)
at async.js:274
at async.js:44
at setImmediate.js:27
at runIfPresent (setImmediate.js:46)
My question is, how do I handle file submission? Is there any better approach for this?
This is much easier to do using the apostrophe-pieces-submit-widgets module, which allows you to define a schema for what the user can submit. You can include a field of type attachment in that, and this is demonstrated in the README.
I've created a react-native project with pouchDB set up. Have installed couchDB. Trying out the same in react native using "pouchdb-react-native". The replication is not happening. I'm getting the error 'message: "getCheckpoint rejected with", name: "unknown"'. Here is following code:
import React, {
Component,
} from 'react';
import {
View,
Image,
StyleSheet,
Text
} from 'react-native';
import PouchDB from 'pouchdb-react-native'
const localDB = new PouchDB('todo');
const remoteDB = new PouchDB('http://username:password#127.0.0.1:5984/todo');
export default class Example extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
// Get records
localDB.allDocs({include_docs: true})
.then(results => {
results.rows.map(row => {
console.log(row.doc);
})
}).catch(err => alert('Err in fetching all records'));
localDB.sync(remoteDB,
function(err, response) {
if (err) {
return console.log(err);
} else {
console.log(response);
}
});
localDB.changes({
live: true,
include_docs: true
}).on('change', () => {
console.log("Event changed in localDB");
this.getAllRecords();
})
.on('complete', () => {
console.log("Event complete in localDB");
this.getAllRecords();
})
.on('error', () => alert("Error"))
}
render() {
return (
<View style={styles.container}>
<Text>Example screen</Text>
</View>
);
}
}
Please help on this. The package.json looks something like this:
"pouchdb": "^6.3.4",
"pouchdb-react-native": "^6.3.4",
"react": "16.0.0-alpha.12",
"react-native": "0.47.2",
What is wrong here? and how can this be debugged?
Also tried replacing the sync portion with below code:
const sync = localDB.sync(remoteDB, {
live: true,
retry: true,
direction: 'from'
});
sync
.on('change', pay_load => {
console.log(" changed!: ");
}).on('paused', info => {
console.log("paused");
}).on('denied', info => {
console.log("paused");
}).on('complete', info => {
console.log("paused");
}).on('active', info => {
console.log("Active");
}).on('error', err => {
console.log("error", err);
}).catch( err => {
console.log("Error: ",err)
});
sync goes only into "paused" state.
I get this same error when I disconnect from the internet. Everything works fine when I reconnect. Maybe troubleshoot your connection ? I am using react native. Also, you may not need pouchdb in your package.json. I just have pouchdb-react-native which drags in the correct pouchDB.
Plus your url has 127.0.0.1 in it. I assume you just used that address to mask the real address or does that address suppose to correspond with a couchDB server you have running on your dev machine. You may need to change that address to the actual address of your couchDB server such as 192.168.1.whatever. I think 127.0.0.1 on your device or simulator will look for a server on the device or simulator not on your dev machine. Hope this helps.
Warren Bell