how to post attachments using Upload Collection - pending - sapui5

I am trying to use the same code wrt official upload collection pending
and in controller where upload is called :
onStartUpload: function(oEvent) {
var oUploadCollection = this.byId("UploadCollection");
var cFiles = oUploadCollection.getItems().length;
var uploadInfo = cFiles + " file(s)";
if (cFiles > 0) {
oUploadCollection.upload();
MessageBox.information("Uploaded " + uploadInfo);
}
},
I have set all required header parameters in onChange as:
onChange: function(oEvent) {
var oUploadCollection = oEvent.getSource();
// Header Token
var oCustomerHeaderEmailToken = new UploadCollectionParameter({
name: "xxxx",
value: xxxxx
});
// Header Token
var oCustomerHeaderAuthToken = new UploadCollectionParameter({
name: "xxxx",
value: "xxxx"
});
oUploadCollection.addHeaderParameter(oCustomerHeaderEmailToken);
oUploadCollection.addHeaderParameter(oCustomerHeaderAuthToken);
},
When i tried uploading in BE it gave me error as :
current request is not a multipart request
Then I tried adding to onChange :
var oCustomerHeaderContentType = new UploadCollectionParameter({
name: "Content-Type",
value: "multipart/form-data; boundary=----WebKitFormBoundarycXEQN6de4OdX0FBe"
});
oUploadCollection.addHeaderParameter(oCustomerHeaderContentType);
It didn't work even though the error is gone ,
The API works fine and tested in postman but why not with upload collection ? May i know the request sent is a multipart form-data ? Do I need to add any extra parameters ?
How does a simple back end API (if JAVA/Python) would be to collect files from when upload collection is used ? as there is no name to refer in server side like fileuploader and if the request is a multipart in upload collection
hope the experts help me out with this ... thanks :)

Related

Google Apps Script: Unable to send emails using createEvent()

I have the following code and attendees are not able to receive emails about the event. Though the event is reflecting in their calendar.
var options = {
description: description,
location: location,
guests: email_address,
sendInvites: true
}
var event = CalendarApp.getCalendarById(calendarId).createEvent(title,
start_datetime, end_datetime,
options);
I have added oauthScopes to appsscript.json as well.
"oauthScopes": [
"https://www.googleapis.com/auth/calendar",
"https://www.google.com/calendar/feeds"
]
It seems like an authorization issue but not sure how to solve this.
You don't need to manually add any scopes while running the script from the browser editor.
Your code worked perfectly for me :) I added a few variables to complete it but it worked just fine -
function myFunction() {
var calendarId = 'self#gmail.com'; // if using your own or default calendar ID
var description = 'test desc';
// ref link - https://developers.google.com/apps-script/reference/calendar/calendar-app#advanced-parameters_4
var email_address = 'contact1#gmail.com, contact2#gmail.com';
// comma separated guest list
var title = 'test title';
var start_datetime = new Date();
var end_datetime = new Date();
var options = {
description: description,
guests: email_address,
sendInvites: true
}
var event = CalendarApp
.getCalendarById(calendarId)
.createEvent(title, start_datetime, end_datetime, options);
}
My default manifest file looks like this -
{
"timeZone": "Asia/Kolkata",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER"
}
No additional scopes seem to have been added. However, when I view my File > Project properties > Scope, only a single scope seem to have been added by the script -
OAuth Scope required by script:
https://www.googleapis.com/auth/calendar
Hope this helps.
Edit note: Forgot to add -
Email notifications are being received as well

Moodle get course information + all lessons through Api

I am trying to collect all information related to Moodle course (course + lessons) Using Moodle Api I got the course information, but gets only some basic information, I want course details and its lessons (created under course)
Eg : var domainname = 'http://<server URL>/moodle';
var token = 'df337369637c692303d903f8cacf1eb0';
var functionname = 'core_course_get_courses';
var serverurl = domainname + '/webservice/rest/server.php' ;
var data = {
wstoken: token,
wsfunction: functionname,
moodlewsrestformat: 'json'
} var response = $.ajax(
{ type: 'GET',
data: data,
url: serverurl
}
);
And the output looks like
{"id":2,"shortname":"IV Support Queries","categoryid":1,"categorysortorder":10001,"fullname":"IV Support Queries","displayname":"IV Support Queries","idnumber":"","summary":"<p>IV Support Queries Desc<br \/><\/p>","summaryformat":1,"format":"topics","showgrades":1,"newsitems":5,"startdate":1479168000,"numsections":5,"maxbytes":0,"showreports":0,"visible":1,"hiddensections":1,"groupmode":0,"groupmodeforce":0,"defaultgroupingid":0,"timecreated":1479127227,"timemodified":1479198758,"enablecompletion":0,"completionnotify":0,"lang":"","forcetheme":"","courseformatoptions":[{"name":"numsections","value":5},{"name":"hiddensections","value":1},{"name":"coursedisplay","value":1}]}
I want the lesson details created under course .How can i get the information through Api . Thanks
Using function
"core_course_get_contents"
getting all the informations related with course.
var domainname = 'http://<server URL>/moodle';
var token = 'df337369637c692303d903f8cacf1eb0';
var functionname = 'core_course_get_contents';
var serverurl = domainname + '/webservice/rest/server.php' ;
var data = {
wstoken: token,
wsfunction: functionname,
moodlewsrestformat: 'json' ,
courseid: 2 //Retrieve results based on course Id 2
}
var response = $.ajax(
{ type: 'GET',
data: data,
url: serverurl
}
);
Thanks

How to send attachments using mailgun?

In my form there is section to upload resume I use mailgun API for my mails to send, I am finding trouble for sending attachments using the form.
How to send the attached file along with other details of my form when user submits.
Please see the below image of my form the attachments should be dynamic but not static.
Example with Node.js
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
var filename = 'mailgun_logo.png';
var filepath = path.join(__dirname, filename);
var file = fs.readFileSync(filepath);
var attch = new mailgun.Attachment({data: file, filename: filename});
var data = {
from: 'Excited User <me#samples.mailgun.org>',
to: 'serobnic#mail.ru',
subject: 'Hello',
text: 'Testing some Mailgun awesomness!',
attachment: attch
};
mailgun.messages().send(data, function (error, body) {
console.log(body);
});

hello, is there a way for consuming a Rest service in an app for windows 8.1 using WinJS?

hello I'm trying to consume a REST service in an app for windows 8.1, I'm so gratefull if you can give me more information related about this topic, thanks !!
You could use the XMLHttpRequest object. But, since you are using WinsJS, the WinJS.xhr function would be more convenient.
Here's an example on how to use it:
(function () {
"use strict";
var app = WinJS.Application;
app.onactivated = function (args) {
// Change RSS feed URL as you need to.
var resDiv = document.getElementById("divResult"),
rssURL = "http://blogs.windows.com/windows/b/appbuilder/rss.aspx";
// Call WinJS.xhr to retrieve an XML feed from the Web.
WinJS.xhr({
url: rssURL,
responseType: "document"
}).done(
// When the result has completed, check the status.
function completed(result) {
if (result.status === 200) {
// Get the XML document from the results.
var xmlDocument = result.responseXML,
title = xmlDocument.getElementsByTagName('title')[0];
// Update the HTML in the app.
resDiv.style.backgroundColor = "lightGreen";
resDiv.innerText = "Downloaded RSS feed from the " + title.textContent + " blog.";
}
});
};
app.start();
})();

Sending POST requests to a nested API endpoint URL using Ember Data

I see several questions on SO attempting to solve this problem of sending POST requests to nested API resource routes.
See:
- [Sending REST requests to a nested API endpoint URL using Ember Data(Sending REST requests to a nested API endpoint URL using Ember Data)
- Custom request URLs in Ember model
I've started overloading the createRecord, updateRecord, and deleteRecord methods on the RESTAdapter to attempt some sort of hackery solution to building the correct URL. Now, using a method similar to this is the route I've taken so far.
Here is the updateRecord method in their solution:
App.UserAdapter = DS.RESTAdapter.extend({
updateRecord: function(store, type, record) {
if(!record.get('parent') || null === record.get('parent')){
return this._super(store, type, record);
}
var data = {};
var serializer = store.serializerFor(type.typeKey);
var parent_type = record.get('parent');
var parent_id = record.get(parent_type).get('id');
var child_parts = Ember.String.decamelize(type.typeKey).split('_');
var path = Ember.String.pluralize(parent_type) + '/' + parent_id + '/' + Ember.String.pluralize(child_parts.pop());
serializer.serializeIntoHash(data, type, record);
var id = record.get('id');
return this.ajax(this.buildURL(path, id), "PUT", { data: data });
}
....
});
This method should work great in tandem with adding the parent type to the model and ensuring the related parent model id is also represented on the model. For PUT and DELETE requests, this shouldn't be a problem, as we already have the parent ID relation on the object in store.
Project model:
App.ProjectModel = DS.Model.extend({
name: DS.attr('string'),
createdAt: DS.attr('date'),
updatedAt: DS.attr('date'),
workspace : DS.belongsTo('workspace'),
parent: 'workspace',
....
});
Where this method appears to go awry for me is in creating new resources with a post. I've attempted it, but since the payload hasn't been returned from the API server with the related parent ID, I actually don't have access to it.
Here's my crappy first attempt, that doesn't work. The workspace id always returns null.
createRecord: function(store, type, record) {
if (!record.get('parent') || null === record.get('parent')){
return this._super(store, type, record);
}
var data = {};
var serializer = store.serializerFor(type.typeKey);
var parent_type = record.get('parent');
var parent_id = record.get(parent_type).get('id');
var path = Ember.String.pluralize(parent_type) + '/' + parent_id + '/' + type.typeKey);
serializer.serializeIntoHash(data, type, record, { includeId: true });
return this.ajax(this._buildURL(path, null), "POST", { data: data });
},
Got any thoughts on how I can get the parent ID, before I have a saved record?
I am the author of the solution you cited in your question.
What does your model hook look like in the route where you are creating the new ProjectModel?
Assuming your Workspace route looks something like:
App.WorkspaceRoute = Ember.Route.extend({
model: function (params) {
return this.store.find('workspace', params.id);
}
});
Then your Workspace Project add/create route's model hook would need to be something like:
App.WorkspaceProjectAddRoute = Ember.Route.extend({
model: function () {
var workspace = this.modelFor('workspace');
return this.store.createRecord('project', {
workspace: workspace
});
}
}
I hope this makes some sense...