I am trying to post an image to the Computer Vision API of Microsoft Cognitive Services. It requires me to upload the image as an url. I have the uploaded image by the user with an URI like http://localhost:9000/content/8a684db8?file=IMG-20160503-WA0002.jpg on my local pc. I tried the obvious but that doesn't work. How to pass the image to their API?
They also mention I can post the image as a raw binary but I am unable to get how to get going.
PS: You can get the subscription keys using the free subscriptions if you want to test it for some other cases.
localhost is 127.0.0.1, e.g. your PC when accessing from your PC. You should pass external IP of your PC in the internet
Well I was able to get a solution. Didn't post my answer sorry.
Microsoft Computer Vision Documentation This shows how to call their API's using the nuget Microsoft.ProjectOxford.Vision.The below code uploads and analyzes a locally stored image to the analyze endpoint of the Computer Vision API service.
using Microsoft.ProjectOxford.Vision;
using Microsoft.ProjectOxford.Vision.Contract;
private async Task<AnalysisResult> UploadAndAnalyzeImage(string imageFilePath)
{
//
// Create Project Oxford Computer Vision API Service client
//
VisionServiceClient VisionServiceClient = new VisionServiceClient(SubscriptionKey);
Log("VisionServiceClient is created");
using (Stream imageFileStream = File.OpenRead(imageFilePath))
{
//
// Analyze the image for all visual features
//
Log("Calling VisionServiceClient.AnalyzeImageAsync()...");
VisualFeature[] visualFeatures = new VisualFeature[] { VisualFeature.Adult, VisualFeature.Categories, VisualFeature.Color, VisualFeature.Description, VisualFeature.Faces, VisualFeature.ImageType, VisualFeature.Tags };
AnalysisResult analysisResult = await VisionServiceClient.AnalyzeImageAsync(imageFileStream, visualFeatures);
return analysisResult;
}
}
On this Git Repository you can see some samples.Here you also get how you can handle client errors and exceptions.
Related
I'm going through the tutorials by AWS Mobile SDK - Xamarin Developer Guide and I want to upload a text file from my Android phone (through Xamarin) to AWS S3. These are the 2 tutorials: Setting Up the AWS Mobile SDK for .NET and Xamarin and Store and Retrieve Files with Amazon S3.
I'm using the method void Amazon.S3.Transfer.TransferUtility.Upload(string,string,string) to upload my text file. I tried running my code but I couldn't. I run into this exception **System.MissingMethodException:** 'Method not found: void Amazon.S3.Transfer.TransferUtility.Upload(string,string,string)' despite the fact that I have included the correct namespaces. I have confirmed that the method void Amazon.S3.Transfer.TransferUtility.Upload(string,string,string) is found in the namespace Amazon.S3.Transfer. Below is my code
client = new AmazonS3Client(credentials, bucketRegion);
var fileTransferUtility = new TransferUtility(client);
fileTransferUtility.Upload(_fileName, bucketName, "toDo.txt");
I've included the correct namespaces, such as using Amazon.S3; using Amazon.S3.Transfer;
The above code works for Windows Presentation Foundation (WPF) Application, but not on Xamarin.
I've add the latest version of
AWSSDK.Core (v3.3.107.8)
AWSSDK.S3 (v3.3.111.9)
How do I resolve this error?
Any help is highly appreciated. Thank you so much in advance.
I have successfully uploaded my text file. Many thanks to #AniketBhansali for suggesting to check for internal exception, and giving UploadAsync a try. Let me detail my debugging process.
In summary, to upload my text file, I
Checked for internal exception
Did UploadAsync
Changed my credentials from the one Amazon Cognito credentials provider gave, to the IAM user I'm using to access my AWS account
For some reason, transferUtility.Upload() is not working, but transferUtility.UploadAsync() is.
So at first I checked for S3 specific exception like this
try
{
var fileTransferUtility = new TransferUtility(client);
fileTransferUtility.Upload(_fileName, bucketName, "toDo.txt");
}
catch(AmazonS3Exception exception)
{
Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", exception.Message);
}
catch (Exception exception)
{
Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", exception.Message);
}
However, the same exception message still occured. So instead of Upload I tried UploadAsync like this
await fileTransferUtility.UploadAsync(_fileName, bucketName, "toDo.txt");
And thankfully, I got a new error message. Unknown encountered on server. Message:'Object reference not set to an instance of an object' when writing an object
I Google Searched and found this Null reference exception with AWS S3 API.
From this question thread, I suspected that the error occured because I was using the credentials from Amazon Cognito credentials provider.
Therefore, I changed the credentials to the IAM user I'm using to access my AWS account and I managed to send my text file to AWS S3.
AWS evolves pretty quickly, so it is possible that they stopped supporting the older methods in their newer SDKs. The latest guide from AWS recommends using transferUtility.Upload(file, bucketName) instead. This is what it should look like:
// Initialize the AWS TransferUtility client
var s3Client = new AmazonS3Client(credentials,region);
var transferUtility = new TransferUtility(s3Client);
// Upload on the Transfer Utility object
transferUtility.Upload(
Path.Combine(Environment.SpecialFolder.ApplicationData,"file"),
"bucketName"
);
I am using the dotNet sdk. All the images are stored in the wwwroot/Image folder i.e. Static folder.
When i am running the bot through emulator i.e. Locally it is showing the image.
But after publishing the application the image is not showing up.
when i debug program remotly then i am getting the proper image path: D:\home\site\wwwroot\wwwroot\Image\pdf.jpg
, which is currect url but sill image is not showing up.
new AdaptiveColumn() {
Width=AdaptiveColumnWidth.Auto,
Items = new List<AdaptiveElement>()
{
new AdaptiveImage()
{
//Url = new Uri(iconUrl),
Size = AdaptiveImageSize.Small,
Style = AdaptiveImageStyle.Default,
UrlString=iconUrl
}
}
},
Any location starting with a drive letter like D is a local path and not a remote URL. You should never use a local path when trying to identify resources on a server, since your bot is communicating with a client on a totally different machine.
Please familiarize yourself with this document to understand how static files work in .NET Core: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files
Once your web app is running on a server, you will be able to access the image using HTTP/S. If you're running the bot locally then the URL should look something like http://localhost:3978/Image/pdf.jpg and if the bot is deployed then it should look something like https://rajatbot.azurewebsites.com/Image/pdf.jpg. Test the URL by pasting it into a browser to make sure it works, then put the URL in your card.
I'm looking for a solution or at least some advice on how to build a function app in c# allowing to backup a tabular database hosted on an SSAS Azure Instance using the REST API. Idea is to backup it on an azure storage.
I've seen several code for SQL but I don't find any relevant documentation or sample.
Thanks for your help,
Miguel
At this moment I've start with this but I've got errors
string ConnectionString = "Provider = MSOLAP; Data Source = asazure://northeurope.asazure.wxxxxxxxxxxxxxxxx";
//
// The using syntax ensures the correct use of the
// Microsoft.AnalysisServices.Tabular.Server object.
//
using (Server server = new Server())
{
server.Connect(ConnectionString); }
I have the following very basic TTS code running on my local server
using System.Speech.Synthesis;
...
SpeechSynthesizer reader = new SpeechSynthesizer();
reader.Speak("This is a test");
This code has a dependency on System.Speech for which I have added a Reference in my VS 2015 project.
Works fine but from what I have read and from trying it I know this will not work when the code is hosted on Azure.
I have read several posts on SO querying if it is actually possible to do TTS on azure. Certainly 2 yrs ago it did not appear to be possible. How to get System.Speech on windows azure websites?
All roads seem to lead to the Microsoft Speech API
https://azure.microsoft.com/en-gb/marketplace/partners/speechapis/speechapis/
I have signed up and have gotten my private and sec keys for calling into this API.
However my question is this. How do I actually call the SpeechAPI? What do I have to change in the simple code example above so that this will work when running on azure?
The speech API you referred to at the Azure marketplace is part of an AI Microsoft project called ProjectOxford which offers an array of APIs for computer vision, speech and language.
These are all RESTful APIs, meaning that you will be constructing HTTP requests to send to a hosted online service in the cloud.
The speech-to-text documentation is available here and you can find sample code for various clients on github. Specifically for C# you can see some code in this sample project.
Please note that ProjectOxford is still in preview (Beta). Additional support for using these APIs can be found on the ProjectOxford MSDN forum.
But just to give you an idea of how your program will look like (taken from the above code sample on github):
AccessTokenInfo token;
// Note: Sign up at http://www.projectoxford.ai for the client credentials.
Authentication auth = new Authentication("Your ClientId goes here", "Your Client Secret goes here");
...
token = auth.GetAccessToken();
...
string requestUri = "https://speech.platform.bing.com/synthesize";
var cortana = new Synthesize(new Synthesize.InputOptions()
{
RequestUri = new Uri(requestUri),
// Text to be spoken.
Text = "Hi, how are you doing?",
VoiceType = Gender.Female,
// Refer to the documentation for complete list of supported locales.
Locale = "en-US",
// You can also customize the output voice. Refer to the documentation to view the different
// voices that the TTS service can output.
VoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)",
// Service can return audio in different output format.
OutputFormat = AudioOutputFormat.Riff16Khz16BitMonoPcm,
AuthorizationToken = "Bearer " + token.access_token,
});
cortana.OnAudioAvailable += PlayAudio;
cortana.OnError += ErrorHandler;
cortana.Speak(CancellationToken.None).Wait();
I am working on integrating my company's product with Jira so users can log bug reports directly from the application. Everything was wqorking smoothly so i decided to import the data from our live Jira system into my development system so that i had some real world data to play with. Since then when i try to get an authtication token it throws the following exception "com.atlassian.crowd.exception.PasswordEncoderNotFoundException: The PasswordEncoder 'atlassian-security' was not found in the Internal Encoders list by the PasswordEncoderFactory". I have checked and the Atlassian Security Password Encoder is enabled in the Crown Password Encoders plugin.
My code is super simple just an ASP.net based text based issues search with the results wired to a grid view code as below:
JiraSoapServiceService service = new JiraSoapServiceService();
string token = service.login("integration", "test");
if (!string.IsNullOrEmpty(txtSearch.Text))
{
RemoteIssue[] issues = service.getIssuesFromTextSearchWithLimit(token, txtSearch.Text, 0, 100);
gvwIssues.DataSource = issues;
gvwIssues.DataBind();
}
I get the error on the call to service.login, it worked fine before I imported the live data. And yes i did add the integration user again after i had imported the data.
Anyone any ideas on this.
No idea what was causing this but rebooting the PC that the dev Jira was installed on fixed it.
EDIT
I have had this a few times now. It tends to happen when you do something like restart the SQL server, restore the jira database via SQL server, restore jira via the inbuilt XML file import method or similar. You don't have to restart the machine just the jira windows service. No idea if this is a problem with other DBs or server types.