Parse.com API create object with file - parse-platform

I'm trying to use Appcelerator Titanium with Parse.com service. Since there is no library for Titanium, I'm using the rest API of Parse.
A Class object on Parse can have a field of type "File". How do I post a file (blob object) to that field?

Here is a starter template application for using Parse with Appcelerator
https://github.com/aaronksaunders/parse-starter-appC
it wraps the parse API in a appcelerator alloy sync adapter
A helper method with allow you to upload the file and associate it with a specific object called a FileHelper. This FileHelper object will provide access to the image
var parseService = require('parseREST');
parseService.init();
file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "iTunesConnect.png");
var blob = file.read();
parseService.uploadFile("image/jpeg", "iTunesConnect.png", blob).then(function(_results) {
return parseService.createObject('FileHelper', {
"nameKey" : _results.response.name,
"fileData" : {
"name" : _results.response.name,
"__type" : "File"
}
}).then(function(_results2) {
console.log("FileHelper Object: " + JSON.stringify(_results2));
},function(_error)
console.log("ERROR: " + JSON.stringify(_error));
});
The results should look something like this:
{
"createdAt": "2015-05-11T15:30:52.004Z",
"objectId": "yLPdeXDinq"
}

Related

how to pass jsonpayload in the CreateAppleTemplateRegistrationAsync notification hub method

I have created a hub client and I want to pass the custom template in the CreateAppleTemplateRegistrationAsync method. I want to pass the below template payload
{ alert: '$(message)', badge: '#(count)', sound: 'default' }
How to pass the above template as a string in the method.
The template payload has to be a valid json string and abide by Apple's documentation.
This is an example of doing it with literal strings in C#.
var apnsTemplate = #"{
""aps"" : {
""alert"" : {
""title"" : ""$(title)"",
""subtitle"" : ""$(subtitle)"",
""body"" : ""$(message)""
},
""category"" : ""GAME_INVITATION""
},
""gameID"" : ""12345678""
}";
This snippet can be adapted for your desired payload and programming language of choice.

apns-collapse-id option not working in FCM

I'm trying to implement APNS notification where i want to maintain single latest notification for all my incoming notification.
I'm using apns-collapse-id which should be supported by FCM as described here
https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages
However when i send multiple notification with single collapse-id the end use is still getting multiple notification
Below is the receiver end payload, which has "gcm.notification.apns-collapse-id" which i'm guessing is being sent by google.
I'm trying to understand if i need to make any changes to make it work.
Original Sender Payload:
{
"to" : "xyz",
"notification": {
"title" : "title_here",
"body" : "body_here",
},
"data" : {
"message" : "Message_Here"
},
"apns-collapse-id" : "STRING_ID_HERE"
"content_available" : true
}
Receiver side Payload:
{
aps = {
alert = {
body = "body_Here";
title = "title_here";
};
"content-available" = 1;
};
"gcm.message_id" = "0:123456789ae";
"gcm.notification.apns-collapse-id" = STRING_ID_HERE;
"google.c.a.e" = 1;
message = "Message_Here";
}
I recommend using the latest send function from the firebase-admin lib, usage described here.
It seems to work fine.

apollo watch method with variables

I am trying to use apollo client watch method in angular to query spring boot server. I am not able to pass arguments with this method.
Since "aid" is mandatory, when it is trying to make a call I getting error like
ERROR Error: GraphQL error: Variable 'aid' has coerced Null value for NonNull type 'String!'
Below is my code in typescript.
export class AgreementGQL extends Query {
document = gql`query agreement($aid: String!) {
agreement(id: $aid) {
id
name
}
}
Below is calling code to the agreement. Where agreement is injected in constructor.
this.agreement.watch({
aid: "1234567"
}).valueChanges.subscribe(result => {
console.log("*********** result : " + JSON.stringify(result.data));
});
I tried using "variables" as well, but no luck.
this.agreement.watch({ variables:{
aid: "1234567"
}}).valueChanges.subscribe(result => {
console.log("*********** result : " + JSON.stringify(result.data));
});
You just need to set the value as a key/value pair like:
const myVal = '123';
Then pass that as an object into the watch method...
const agreement = this.agreementQuery
.watch({ myVal })
.valueChanges.pipe(pluck('data'));
Then Subscribe to get the data out:
agreement.subscribe(data => console.log(data));
This approach worked for me.

EasyPost Create Webhook returns null

I tried to create an easy post webhook using easy post in asp.net core API project. it returns a null value in webhook creations.
i tried this
using EasyPost;
EasyPost.ClientManager.SetCurrent("<YOUR_TEST/PRODUCTION_API_KEY>");
Webhook webhook = Webhook.Create(
new Dictionary<string, object>() {
{ "url", "https://www.foobar.com" }
}
);
I was able to have the webhook create method return JSON properly by using the most current version of the C# client library. This is the code snippet I used:
using System;
using System.Collections.Generic;
using EasyPost;
using Newtonsoft.Json;
namespace create_webhook
{
class createWebhook
{
static void Main(string[] args)
{
EasyPost.ClientManager.SetCurrent(Environment.GetEnvironmentVariable("EASYPOST_API_KEY"));
Webhook webhook = Webhook.Create(
new Dictionary<string, object>() {
{ "url", "https://www.foobar.com" }
}
);
Console.WriteLine(JsonConvert.SerializeObject(webhook, Formatting.Indented));
}
}
}
Response:
{
"id": "hook_123...",
"mode": "test",
"url": "https://www.foobar.com",
"disabled_at": null
}
For reference, the API docs related to creating a webhook for C# do not specifically mention to print what is returned which is why in my example I added a print statement.

Associate File in Parse.Cloud

I am uploading an image through REST API and getting an answer as below
{
"url": "http://files.parsetfss.com/346a0978-68c7-4d08-a446-62f7422469e7/tfss-8b131ff0-5fd0-4dce-92e8-b7b94da5db9e-pic.jpg",
"name": "tfss-8b131ff0-5fd0-4dce-92e8-b7b94da5db9e-pic.jpg"
}
I want to associate this image to a Promotion object. I also have a Location object which has an array of Promotions. Here is my code:
function promiseToAddPromotionToLocation (locationID, promotion) {
var query = new Parse.Query("Location");
return query.get(locationID).then(function (location) {
var promotionObject = promotionObjectFromJSON(promotion);
location.add("promotions", promotionObject);
return location.save();
}, function (error) {
return Parse.Promise.error(error);
});
}
function promotionObjectFromJSON (promotion) {
var Promotion = Parse.Object.extend("Promotion");
var promotionObject = new Promotion();
if ("message" in promotion) {
promotionObject.set("message", promotion.message);
}
//This causes an error: Uncaught Tried to save an object containing an unsaved file.
if ("photo") {
promotionObject.set("photo", promotion.photo);
}
return promotionObject;
}
When I comment out the part of setting photo, it saves the promotion properly, but when I try to set the file, it gives an error saying Uncaught Tried to save an object containing an unsaved file. How can I solve this problem?
By the way promiseToAddPromotionToLocation is called with the parameters below:
{
"locationID": "fvOiAsoogc",
"promotion":{
"message":"Some text",
"photo":{"name": "tfss-8b131ff0-5fd0-4dce-92e8-b7b94da5db9e-pic.jpg", "__type": "File"}
}
}
The reason was that I was passing the file info without url. Associating file docs show that it only needs name and type. However, this is wrong. It also needs the url. This question in Parse forum reveals it.

Resources