windows azure script services add message to queue - mobile

I'm using Windows Azure Mobile services to upload pictures from a mobile app. The mobile script services accepts the file, saves it's name to the database.
What I'm trying to do is to be able to add a message to a queue which will resize the uploaded image.
Do Script services supports calling queues from within or I have to make my app do that call?
Thanks in advance

You can use the following code to send a message to the queue:
var azure = require('azure');
var queueService = azure.createQueueService("myaccount", "mykey");
queueService.createQueueIfNotExists("myqueuename", function(error){ });
queueService.createMessage("myqueuename", "contentOfTheMessage", function(error){});

Related

Email does not send in Laravel API after writing to database

I have an AngularJS 1.5 application which is working with a Laravel 5.2 API and I'm trying to send emails at different points in the application. So I'm able to send data to Laravel and it gets recorded in the tables I specify but when it gets to sending a confirmation email it gives me this error with an HTTP status code of 500: MethodNotAllowedHttpException
Odd thing is, it works perfectly fine in local development on my laptop. But the same functions on the AWS EC2 instance and it fails when it gets to sending any email. I'm using SendGrid to manage sending emails but I don't think I need to change any settings for that.
For Example:
$emailUser = array();
$emailUser['email'] = $request->email;
$emailUser['first_name'] = $request->first_name;
$emailUser['last_name'] = $request->last_name;
$emailUser['randomStr'] = str_random(36);
$emailUser['remove_dtm'] = Carbon::now()->addWeeks(2);
//Add a password reset set to 2 weeks out for the user to register
DB::table('password_resets')->insert([
'email' => $emailUser['email'],
'token' => $emailUser['randomStr'],
'remove_dtm' => $emailUser['remove_dtm']
]);
Mail::send('email.registered_user', $emailUser, function($message) use ($emailUser)
{ $message->to($emailUser['email'], $emailUser['first_name'] . ' ' . $emailUser['last_name']);
$message->from('WSCUSTOMERPO#waterstoneco.com', 'Waterstone Faucets');
$message->replyTo('WSCUSTOMERPO#waterstoneco.com', 'Waterstone Faucets');
$message->subject("Welcome to the Waterstone Faucets Portal!");
});
When I try to reset a user's password it will create the record in the password_reset table but not send the email on the live site. Again the same function works fine on my laptop. I checked that I'm posting on the Angular side and Laravel API is expecting a post HTTP call when running this function.
What am I missing here?
Thank you greatly for your help!
There are a few things to check here,
1: Are you sure you have your .env file set up to use the correct SMTP server settings to use SendGrid. If you forgot to set this up in your .env you will be using the internal mail function. Instead of using SendGrid, I would suggest keeping it inside of Amazon for more reliability. Switching over to Amazon SES may be a great option for you.
2: If you are using the internal mail system, there is a really good article about mail from Amazon EC2 instances here: http://shlomoswidler.com/2009/07/sending-email-from-ec2.html
Just a reminder for number 1 for others that may have come here looking for help. To set your mail service in Laravel to use an smtp service, open your config/mail.php file and set the driver to use your provider (if provided by laravel). This can be done by edit the file directly or setting the environment variable MAIL_DRIVER in your .env file.

How to troubleshoot "Value cannot be null. Parameter name: baseUri"

I need help diagnosing this error. Others get it on various platforms (youtube, for example) but seems not solved for most of them. For those who do report success, their solutions haven't work for me.
I'm using Google Drive API and I receive this error when attempting to upload to Google Drive.
My code was working fine for a long time; suddenly, I get this error. After research, I determined that I haven't reached a quota, and that these API are enabled:
Debuglet Controller API
Drive API
Google Cloud Dataflow API
Google Cloud Dataproc API
Google Cloud Deployment Manager API
Google Cloud Deployment Manager V2 API
Google Cloud Storage
Google Cloud Storage JSON API
Google Compute Engine Autoscaler API
Google Compute Engine Instance Group Manager API
Google Compute Engine Instance Group Updater API
Google Compute Engine Instance Groups API
Google Container Engine API
Google Machine Learning API
Here's my code:
string fileName = #"c:\temp\MyPicture.jpg";
string fileTitle = #"TEST-DELETE-ME.jpg";
string fileDescription = #"Test file name";
string fileType = "image/jpeg";
string parentId = "zmzmzmzmzmzmzmzmzmz";
Google.Apis.Drive.v2.DriveService service = (Google.Apis.Drive.v2.DriveService)Service;
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
body.Title = fileTitle;
body.Description = fileDescription;
body.MimeType = fileType;
body.Parents = new List<ParentReference> { new ParentReference() { Id = parentId } };
byte[] byteArray = System.IO.File.ReadAllBytes(fileName);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
Google.Apis.Drive.v2.FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, fileType);
Google.Apis.Upload.IUploadProgress progress = request.Upload();
Google.Apis.Drive.v2.Data.File file = request.ResponseBody;
if (file == null)
{
//Here we are, and we shouldn't be!
//progress.exception.message =
//
//Value cannot be null.
//Parameter name: baseUri
}
When I look at Drive API settings, these are the configurations:
No icons (there are boxes to set 256x265, 128x128, 64x64, 32x32, and 16x16 all are blank)
The application name and short and long descriptions are all blank and optional.
For Drive Integration, all boxes and checkboxes are blank or unchecked. Specifically:
"Automatically show OAuth 2.0 consent..." is unchecked.
"Open URL" is blank.
Default and secondary MIME types and file extensions are blank
"Allow users to create new documents..." is unchecked
"Allow users to open multiple files..." is unchecked
"Allow users to open files that can be converted..." is unchecked
"This application can be launched and works properly in a mobile browser" is unchecked.
Users don't use the Google Drive UI to create documents via my application, and is not meant to be used on a mobile browser. My application only uploads PDF files to users' accounts.
My application has been working for months with no problems, now suddenly seeing this error.
I have tried disabling all API's and then re-enabling them. No dice.
I have tried using a new client id and secret. No dice.
I have tried using a new gmail address and creating a new client id and secret. No dice.
I can't possibly be the only person in the world with this problem. Can anyone help me troubleshoot this?
The underlying issue is like an authorization issue or some other error with the request. However, there's a bug in the .NET client that is masking the error.
See https://github.com/google/google-api-dotnet-client/issues/456

Database and DB provider for hybrid mobile app

I am new to hybrid mobile app development. I am coming from web based development background so bit perplexed.
I zeroed down on Apache/Cordova for build/packaging my hybrid mobile app. This app would be hosted on all 3 major stores. After my initial research, I got a good flavor of UI pieces/frameworks e.g. Angular, Bootstrap, etc. One thing where I got so confused is back-end storage, services and provider. In other words,
What storage services do i need for storing and pulling data (not offline app data)?
Based on storage service how do I decide on provider. Any guidance?
Best way for making calls for all my CRUD operations?
Do I need any kind of server side operations or client side JS would suffice?
Thanks for your help.
You can use Azure Mobile service to store and pull data, each mobile service comes with database. You can try out the trial version to see whether it meets your requirement.
Follow the below steps to add Azure mobile service to your project through Visual Studio:
1.) Right click on project node and select Add --> Connected Services.
2.) Sign-in with your Azure account. Click on Create Service to create new mobile service.
3.) Select the newly created mobile service and click Ok.
4.) It will add service.js, which contains Azure mobile service object.
5.) You can use Azure mobile service object to perform CRUD operations like
var CordovaAppClient
document.addEventListener("deviceready", function () {
CordovaAppClient = new WindowsAzure.MobileServiceClient(
"https://Dummyapp.azure-mobile.net/",
"IsBLy-----ScCqDMuCCZqVlF------");
});
function ReadData()
{
var table = CordovaAppClient.getTable("Item");
var query = table.where({ complete: true });
query.read().then(function(items)
{
listItems = $.map(items, function (item) {
alert(item.text);
});
});
}
function InsertData()
{
var table = CordovaAppClient.getTable("Item");
var inputTest = $('#txtData').val();
table.insert({ text: inputTest, complete: false })
.then(addmessage);
}

Calling GAS Script published as a Service from GWT

I have created a Google Apps Script doPost script that I have published as a Service, only available to myself (as described in https://developers.google.com/apps-script/guide_user_interfaces#RunDecision, section "Publishing a Script as a Service").
I have now a URL like https://sites.google.com/a/macros/[google apps domain]/exec?service=[service key]
I want to call this service from a Google App Engine GWT application, but I don't know how to manage with authentication.
If selecting the "Allow anyone to invoke this service" then "Allow anonymous access", then I can call this service from AppEngine, but in my case, I absolutely need the authentication.
Do you have any idea how to handle it ?
If you only need to call this script from server to server and both of the endpoints are in your ownership, you could use a shared secret to do so, e.g.
Apps Script:
function doPost(e) {
if(e.parameters.secret != 'mysecret') {
return ContentService.createTextOutput("Nice try!");
}
// your code here
}
and transmit it with the request. If you only share your script with "Anyone having the link" that should provide reasonable security - make sure you never log that request nor include it in an error message however ;)

Adding attachments to workitems from silverlight

For a project we need to add attachments to workitems through a Silverlight application.
Our Silverlight app has a WCF service with which it communicates to our TFS 2010 server with the TFS API.
I can bind attachments from within the WCF service just fine, however what are the best practices to do this through Silverlight, seeing that SL is clientside and the WCF service serverside?
The way I look at it is that I need to upload the attachment to the server first, add the workitemid and the serverpath of the newly uploaded file, in some sort of log. Run a process/application on the server which searches the log for new entries, and then call the webservice which will add the attachment to the workitem.
Is this the best way to go?
Any help or suggestions would be greatly appreciated.
I would generally approach this as you described, without creating the intermediate logfile:
Upload the attachment using your SL client to the server.
Calculate the serverpath of the attachment.
Call the WCF service to process the attachment and specify the serverpath and workitem id.
Thank you Kroonwijk, for your suggestions on how to make the approach somewhat simpeler.
In the end I processed the file(s) to a byte[] on the Silverlight client side.
This byte[] is sent to the webservice accompanied by a workitemID. On the Server side(webservice) the byte[] gets saved to a temporary file on the server, and gets attached and saved to the workitem.
All works well with one WCF call, without having to use a process or file transfers to the server.
Point of notice: you might have to increase the message quota limit in your WCF bindings.

Resources