Blob upload with axios fail in Laravel - laravel

I have been trying to upload files using axios, the payload on the console network tab looks great but the files appear to be empty on the Laravel side.
Below is the response I get from $request->all()
"feedback": {
"description": "there is not a friend",
"displays": [
"Lagos -\r\n Ikoyi"
],
"messages": [
{
"text": "this is an unexpected result",
"startTime": "2018-02-20T11:11:01.404Z",
"endTime": "2018-02-20T11:11:01.411Z",
"image": {},
"video": {}
}
]
}
}
Below is the send method:
submit() {
const data = new FormData();
data.append('description', this.description);
for (let index in this.boards) {
if (this.boards.hasOwnProperty(index)) {
data.append('displays[' + index + ']', this.boards[index]);
}
}
for (let index in this.messages) {
if (this.messages.hasOwnProperty(index)) {
data.append('messages[' + index + '][text]', this.messages[index].text);
data.append('messages[' + index + '][image]', this.messages[index].imageBlob);
data.append('messages[' + index + '][video]', this.messages[index].videoBlob);
data.append('messages[' + index + '][startTime]', this.messages[index].startTime);
data.append('messages[' + index + '][endTime]', this.messages[index].endTime);
}
}
axios.post('/campaign/', data, {
headers: {
'accept': 'application/json',
'Accept-Language': 'en-US,en;q=0.8',
'Content-Type': `multipart/form-data; boundary=${data._boundary}`,
}
}).then(response => {
this.feedback = response.data;
}).catch(error=>{
this.errors = error
});
}
Please, how can I work around that?

Related

how to force a AWS Lambda to complete all the code

I have a lambda that is inserting a record into an Airtable db. This should be pretty straight forward and I have it working locally.
Once I put it into Lambda the record is not inserted. I have been messing with this for 2 days and can't figure out why the record won't load into Airtable.
The only other note that matters is that this lambda is long polling for SQS messages.
console.log('Loading function');
const Airtable = require('airtable');
const apiKey = process.env.AIRTABLE_API_KEY;
const BaseTable = process.env.AIRTABLE_BASE_TABLE;
var base = new Airtable({
apiKey: apiKey
}).base(BaseTable);
const table = base('Contacts');
exports.handler = async (event) => {
for (const {
messageId,
body
} of event.Records) {
console.log("iteration: " + iteration);
const data = JSON.parse(body);
var fields = {
"Full Name (First Middle Last)": data.firstname + ' ' + data.lastname,
"Email": data.email,
"Phone": data.phonenumber,
"Address": data.address_one + ' ' + data.address_two,
"City": data.city,
"State/Province": data.state,
"Postal Code": data.zip,
"Country": data.country,
"Birthday": data.dob,
};
insertRecord(fields);
}
console.log('before the end');
};
function insertRecord(fields) {
console.log('insert Record');
return new Promise((resolve, reject) => {
table.create([{
fields: fields
}], function(err, records) {
if (err) {
console.log('ERROR');
console.log(err);
reject(err);
} else {
console.log('SUCCESS');
resolve(records);
}
});
});
}
I have been googling, and reviewing, others' answers for multiple days now.

How can I iterate over the test data using webdriverio with mocha?

I have a JSON based test data, how can I iterate over this test data for the test to run for each cred object?
cred: {
nameValue: 'ant',
emailValue: 'ant#gmail.com',
passwordValue: 'ant',
},
cred: {
nameValue: 'bat',
emailValue: 'bat#gmail.com',
passwordValue: 'bat',
},
your test data JSON file should be like this,
[
{
"nameValue": "ant",
"emailValue": "ant#gmail.com",
"passwordValue": "ant"
},
{
"nameValue": "bat",
"emailValue": "bat#gmail.com",
"passwordValue": "bat"
}
]
Now you can access them by index ( as in an array )
const testDataObject = require("path to testData json");
// to loop on all elements
testDataObject.forEach(function(element) {
it(' test case def ', function() {
console.log("nameValue "+ element['nameValue']+ "emailValue
"+element['emailValue'] + "passwordValue "+element[passwordValue]);
});
});
// to select any particular index
it(' test case def ', function() {
console.log("nameValue "+ testDataObject[1]['nameValue']+ "emailValue
"+testDataObject[1]['emailValue'] + "passwordValue "+testDataObject[1][passwordValue]);
});
});
And name your testData file name as Credentials_Valid.json ( best practice )
or
you can do in this way
{
"cred1":
{
"nameValue": "ant",
"emailValue": "ant#gmail.com",
"passwordValue": "ant",
},
"cred2":
{
"nameValue": "bat",
"emailValue": "bat#gmail.com",
"passwordValue": "bat",
}
}
and access the test data in nodejs code by
console.log( `${testDataObject['cred1']["nameValue"]}` );
console.log( `${testDataObject['cred1']["emailValue"]}` );
console.log( `${testDataObject['cred1']["passwordValue"]}` );

How to use the post_poll method in Zapier CLI

According to the docs, I should use a post_poll function to add the missing id field in the response.
How do I add the post_poll function ?
Here's my error:
Results must be an array, got: object,
({"totalevents":83,"events":[{"eventid":10266033,"c)
- Got a result missing the "id" property (83)
Tried following this but it is not clear to me, I'm very new to Zapier-CLI
Update - adding code
This is the function that returns the data:
const listEvents = (z, bundle) => {
console.log('listing events.. ');
let client_id = bundle.inputData.client_id;
const requestOpts = {
url: `https://wccqa.on24.com/wcc/api/v2/client/${client_id}/event`
};
return z.request(requestOpts)
.then((response) => {
return z.JSON.parse(response.content);
});
};
The sample response is the following, with the distiction that I added the id param manually to avoid errors when zapier test|push:
{
"id": 9964513,
"eventid": 9964513,
"archivestart": "2017-09-21T10:30:00-07:00",
"archiveend": "2018-09-21T10:30:00-07:00",
"description": "Zapier Event Test",
"iseliteexpired": "N",
"displaytimezonecd": "America/Bogota",
"eventtype": "Live Webcam ",
"regrequired": true,
"clientid": 22921,
"liveend": "2017-09-21T10:00:00-07:00",
"createtimestamp": "2017-09-21T09:47:44-07:00",
"audienceurl": "https://localhost.on24.com/wcc/r/9964513/C49755A02229BD48E6010848D7C81EF8",
"lastmodified": "2017-09-21T09:47:44-07:00",
"livestart": "2017-09-21T08:45:00-07:00",
"goodafter": "2017-09-21T09:00:00-07:00",
"regnotificationrequired": true,
"isactive": true,
"localelanguagecd": "en"
}
The ACTUAL response from the endpoint the following which is used in the app created in the Web Builder App instead of CLI and works fine:
{
"events": [
{
"eventid": 9964513,
"archivestart": "2017-09-21T10:30:00-07:00",
"archiveend": "2018-09-21T10:30:00-07:00",
"description": "Zapier Event Test",
"iseliteexpired": "N",
"displaytimezonecd": "America/Bogota",
"eventtype": "Live Webcam ",
"regrequired": true,
"clientid": 22921,
"liveend": "2017-09-21T10:00:00-07:00",
"createtimestamp": "2017-09-21T09:47:44-07:00",
"audienceurl": "https://localhost.on24.com/wcc/r/9964513/C49755A02229BD48E6010848D7C81EF8",
"lastmodified": "2017-09-21T09:47:44-07:00",
"livestart": "2017-09-21T08:45:00-07:00",
"goodafter": "2017-09-21T09:00:00-07:00",
"regnotificationrequired": true,
"isactive": true,
"localelanguagecd": "en"
}
],
"totalevents": 1
}
I was thinking something along the line of the following, but how do I register this ?
const postPoll = (event,z,bundle) => {
if(event.key === 'events'){
var results = z.JSON.parse(bundle.request.data).results;
var events = results.events.map(function(event){
event.id = event.eventid;
return event;
});
bundle.request.data = events;
}
};
module.exports = postPoll;
Nice, so you're almost there! CLI apps don't have pre_ and post_ poll methods. Instead, you put any manipulation after the response comes in.
const listEvents = (z, bundle) => {
console.log('listing events.. ');
let client_id = bundle.inputData.client_id;
const requestOpts = {
url: `https://wccqa.on24.com/wcc/api/v2/client/${client_id}/event`
};
return z.request(requestOpts)
.then((response) => {
return z.JSON.parse(response.content);
})
.then(data => {
const events = data.events; // array of events
return events.map(function(e){ // returns array of objects with `id` defined
e.id = e.event_id
return e
})
})
};

Is it possible to have more than one URL in the webRequest target

Is it possible to have more than one target in the urls argument in the webRequest. How?
This is an example that did not work and gave me this error:
The webRequest.addListener filter doesn't overlap with host permissions.
****UPDATED****:
This is the example code main.js:
myArray=["yahoo.com", "google.co.uk"];
patterns=[];
for (var x=0; x<myArray.length; x++)
{
var aURL="\"https://*."+myArray[x]+"/*\""
patterns.push(aURL);
}//end for
console.log("the array: "+patterns);
function logURL(requestDetails)
{
console.log("inside logURL");
console.log("*******************************");
console.log("Loading: " + requestDetails.url);
console.log("*******************************");
}//end logUTL
browser.webRequest.onBeforeRequest.addListener(
logURL,
{urls: patterns,
types: ["main_frame"]}
);
This is the manifest:
{
"manifest_version": 2,
"name": "test",
"version": "1.0",
"description": "",
"background": {
"scripts": ["main.js"]
},
"icons": {
"64": "icons/myicon.png"
},
"permissions":[
"<all_urls>",
"activeTab",
"tabs",
"activeTab",
"webRequest"
]
}
You have to use an array for the patterns.
myArray=["yahoo.com", "google.co.uk"];
patterns=myArray.map(item=>`https://*.${item}/*`)
console.log("the array: "+patterns);
function logURL(requestDetails)
{
console.log("inside logURL");
console.log("*******************************");
console.log("Loading: " + requestDetails.url);
console.log("*******************************");
}//end logUTL
browser.webRequest.onBeforeRequest.addListener(
logURL,
{urls: patterns,
types: ["main_frame","xmlhttprequest"]}
);
The second parameter of addListener is a RequestFilter.
Any reason to add double quotes?
-var aURL="\"https://*." + myArray[x] + "/*\""
+var aURL="https://*." + myArray[x] + "/*"

Lambda and API gateway mapping

I want to return a value from handler to API gateway response header.
Handler.js
module.exports.handler = function(event, context, cb) {
const UpdateDate = new Date();
return cb(null, {
body: {
message: 'test'
},
header: {
Last-Modified: UpdateDate
}
});
};
s-function.json in "endpoints"
"responses": {
"400": {
"statusCode": "400"
},
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Cache-Control": "'public, max-age=86400'",
"method.response.header.Last-Modified": "integration.response.body.header.Last-Modified"
},
"responseModels": {
"application/json;charset=UTF-8": "Empty"
},
"responseTemplates": {
"application/json;charset=UTF-8": "$input.json('$.body')"
}
}
}
This can work. But I want to know how to use "integration.response.header.Last-Modified". Is my handler callback formate wrong?
Edit:
s-function.json in "endpoints"
"integration.response.header.Last-Modified" This doesn't work.
I want to know specific handler return formate to pass data to "integration.response.header.Last-Modified".
"responses": {
"400": {
"statusCode": "400"
},
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Cache-Control": "'public, max-age=86400'",
"method.response.header.Last-Modified": "integration.response.header.Last-Modified"
},
"responseModels": {
"application/json;charset=UTF-8": "Empty"
},
"responseTemplates": {
"application/json;charset=UTF-8": "$input.json('$.body')"
}
}
}
All of the output from your lambda function is returned in the response body, so you will need to map part of the response body to your API response header.
module.exports.handler = function(event, context, cb) {
const UpdateDate = new Date();
return cb(null, {
message: 'test',
Last-Modified: UpdateDate
});
};
will produce payload "{"message" : "test", "Last-Modified" : "..."}"
In this case you would use "integration.response.body.Last-Modified" as the mapping expression. As a side note, naming things "body" and "header" in your response body may make the mapping expressions confusing to read.
Thanks,
Ryan

Resources