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.
Related
We have a wcf service that uses DevExpress XtraReports to generate a pdf file.
How this normally works is we have in the web.config the physical directory Example C:\PdfDocs\ that we specify as the path when executing the devexpress ExportToPdf function. This works fine on a normal virtual machine.
We are now busy moving to Microsoft Azure enviroment and I am having trouble getting this to work.
My Setup - The wcf service is created as a App Service. Unfortunately I am not at liberty to give names so lets assume the following:
App Service Name - testdocservice,
Url Azure gives - https://testdocservices.azurewebsites.net
What I have tried:
In Application settings, I have created a virtual directory. In the project itself I have created a folder that the virtual directory will point to.
The virtual path is https://testdocservices.azurewebsites.net/ItinDocs and the physical path is site\wwwroot\ItinDocuments
This is setup correctly as I have tested it by FTP test pdf in and then hit the following url: https://testdocservices.azurewebsites.net/ItinDocs/test.pdf
So in the wcf service I took a chance and set the location to render the pdf to "site\wwwroot\ItinDocuments" - This did not work.
The exception was as follows: Access to the path 'D:\Windows\system32\site\wwwroot\ItinDocuments\TestQuote21.pdf' is denied.
I then tried using Server.MapPath example:
QuoteV3 oQuote = new QuoteV3();
oQuote.DataSource = dSource;
oQuote.ExportToPdf(System.Web.HttpContext.Current.Server.MapPath($"~{ConfigurationManager.AppSettings["DocLocation"]}{fileName}"));
The DocLocation look like the following: site\wwwroot\ItinDocuments\
This also did not work. The following error is given:
'~https:/testdocservices.azurewebsites.net/ItinDocs/TestQuote21.pdf' is not a valid virtual path.
I thought the first character "~" could be a problem so I removed it and got the same error as above - 'https:/testdocservices.azurewebsites.net/ItinDocs/TravelQuote21.pdf' is not a valid virtual path.
I then noticed that the above errors only have one forward-slash after the https. At this point I am not sure if that could be causing the problem and then how to correct it as the Server.MapPath is generating that part.
In conclusion, I am not sure if I am even working in the right direction with the above approach. My knowledge around azure is still minimal.
Any help/assistance/solution would be greatly appreciated.
Many thanks.
This can be closed as I have instead setup azure storage and my pdfs are saving in a container instead.
Thanks.
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.
I'm using dotnet-mammoth (mammoth.js with edge.js) to convert a docx document to html in .net
I added it to my project via its nuget package.
I'm using the code provided by the sample, which is working correctly in my development enviroment (running IIS Express):
var documentConverter = new Mammoth.DocumentConverter();
var result = documentConverter.ConvertToHtml(Server.MapPath("~/files/document.docx")); // problem here at production enviroment
string theResult = result.Value
However, once I deploy it to production server, when the executed code reaches documentConverter.ConvertToHtml() method, it's redirecting me to the login page. Without displaying any error messages, without saving anything on IIS log file.
If I remove that line, everything else executes normally.
I assume it could be an issue related to permissions but I don't know what could it be. Any ideas?
The latest version of Mammoth on NuGet no longer uses edge.js, and is now just .NET code, so should work more reliably.
You can resolve this by getting the exact error when the process is trying to read the file. Below is the code from dotnet-mammoth DocumentConverter.cs. As shown below on call it is trying to read all bytes to be sent to edge
public Result<string> ConvertToHtml(string path)
{
var mammothJs = ReadResource("Mammoth.mammoth.browser.js") + ReadResource("Mammoth.mammoth.edge.js");
var f = Edge.Func(mammothJs);
var result = f(File.ReadAllBytes(path));
Task.WaitAll(result);
return ReadResult(result.Result);
}
I suppose you are giving absolute path to the input. In that case the absolute path should be accessible by app identity hosting the app pool of the web application.
If the path specified is in web root directory - (not advised) - but if it is then you can use Server.MapPath
I just mounted a web site locally with IIS manager. I can access the site from the path http://192.168.154.2/Default.aspx and I have a folder named Affiche which contains some images and is situated in a remote server from the same network.
To access an image I am using an aspx page GetImage.aspx which work like this:
var path = "//192.168.84.52/Distri/Affiche/10038P.jpg"
if ((string.IsNullOrEmpty(imageName) == false))
{
try
{
// Retrieving the image
System.Drawing.Image fullSizeImg;
fullSizeImg = System.Drawing.Image.FromFile(path);
// Writing the image directly to the output stream
fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg);
// Cleaning up the image
fullSizeImg.Dispose();
}
catch (System.IO.FileNotFoundException)
{
//MessageBox.Show("There was an error opening the bitmap." +
// "Please check the path.");
}
}
This solution works fine in localhost ( with Visual Studio), I an perfectly get the image with a link like this http://localhost:3606/GetImage.aspx, however http://192.168.154.2/GetImage.aspx does not work. It will only show a broken image icon.
The remote can be accessed from my computer ( which already input the login) where I have installed the web server.
I tried another solution by using this solution : a virtual directory
From the IIS manager I can perfectly view the files from the remote server, but when I try to access the virtual folder like this: http://192.168.154.2/afficheImage/20772G.jpg
I have an 500.19 error with insufficient permissions.
Is there a way to solve this please?
The first line of your code:
var path = "//192.168.84.52/Distri/Affiche/10038P.jpg"
This is pointing to a different IP address than your website having virtual directory. "192.168.154.2". Are you accessing images from another server? In that case you need to check permissions on another server as well.
Use the below line of code for path
var path = #"\\192.168.84.52\Distri\Affiche\10038P.jpg"
This is correct notation but you gave invalid slashes.
I have an ASP.NET MVC Web Site ,the user can upload a video and When Done It finish uploading I show him an image extracted from the Video,
To do this I used the FFMPEG exe to get a frame.
Everthing works well in the developement machine , when I use the test environement it does not work!!
I've given the read/write and execute permissions to following folders:
1. videos(folder that store uploaded video files)
2. thumbnails (folder that store the thumbnails of videos, captured by ffmpeg)
3.ffmpeg.exe file at root and given read/write execute permissions to that file also.
but it does not work.
var _converter = new ImageConvertor(#System.Configuration.ConfigurationManager.AppSettings["FFmpegExec"].ToString());
_converter.WorkingPath = Server.MapPath("~/VideoSamples");
OutputPackage oo = _converter.ConvertToFLV(videoFilepath);
FileStream outStream = System.IO.File.OpenWrite(Path.Combine(Server.MapPath("~/VideoSamples"), id.ToString() + ".flv"));
oo.VideoStream.WriteTo(outStream);
This Code Works on developement env but not in test env !!!
Any Ideas Please