I'm just trying to check browser compatibility with images and videos in the Reactjs website application. If the extension of the image/video does not support, then it has to show a alert message or an action. how to do this ?
Tried Modernizr
I tried, the given code is working for me :
videoBrowserSupportValidation() {
const extension = filename.split('.').pop(); // This is to get extenstion of your video file and filename is video file name
const vidpath1 = "video/";
var obj = document.createElement('video');
var videoType = obj.canPlayType(vidpath1+extension);
if (videoType == "") {
console.log("Invalid file , browser does not recognize video formats ");
// write your action
}
else {
console.log("Valid file");
// write your action
}
Related
//If the user uploaded an image, read it, and send it to the Vision API
if (activity.Attachments.Any() && activity.Attachments.First().ContentType.Contains("image"))
{
//stores image url (parsed from attachment or mess`enter code here`age)
string uploadedImageUrl = activity.Attachments.First().ContentUrl; ;
uploadedImageUrl = HttpUtility.UrlDecode(uploadedImageUrl.Substring(uploadedImageUrl.IndexOf("file=") + 5));
using (Stream imageFileStream = File.OpenRead(uploadedImageUrl))
{
try
{
analysisResult = await visionClient.AnalyzeImageAsync(imageFileStream, visualFeatures);
}
catch (Exception e)
{
analysisResult = null; //on error, reset analysis result to null
}
}
}
//Else, if the user did not upload an image, determine if the message contains a url, and send it to the Vision API
else
{
try
{
analysisResult = await visionClient.AnalyzeImageAsync(activity.Text, visualFeatures);
}
catch (Exception e)
{
analysisResult = null; //on error, reset analysis result to null
}
}
I am trying the code above. I got the code from here: https://docs.botframework.com/en-us/bot-intelligence/vision/#example-vision-bot.
As is, the code does what it can do when ran locally, but reading the image's URL from an uploaded file doesn't work after I published my bot to Azure and ran it from there.
I attempted to debug by attaching Visual Studio directly to my published webapp bot in Azure. It looked like the webapp is unable read the stored image's URL from the Azure server temp storage location or can't access the temp storage location.
This line:
uploadedImageUrl = HttpUtility.UrlDecode(uploadedImageUrl.Substring(uploadedImageUrl.IndexOf("file=") + 5));
Shows this value:
"https://bcattachmentsprod.blob.core.windows.net/at4984/Gv4cOx6OdSl- original"
Then, this line:
using (Stream imageFileStream = File.OpenRead(uploadedImageUrl))
Changes the value to:
"s://bcattachmentsprod.blob.core.windows.net/at4984/Gv4cOx6OdSl-original"
And then it just stops.
Has anyone ran into an issue like this? How do I go about solving this issue?
Thanks!
If you have a image URL, you should simply call AnalyzeImageAsync with that URL instead of creating a stream as you have. The File class should be used for files on your local drive/network. By creating a stream, you download the image once to your VM, then upload it to the vision service, doubling the work.
I am trying to create a program that will download image files in my google drive. I was able to do so, however when I am trying to search a file to return a specific file I always got an error when using the 'name' field which is base on this website https://developers.google.com/drive/v3/web/search-parameters. I don't really know the problem. This is my code
GoogleHelper gh = new GoogleHelper();//calling
DriveService service = GoogleHelper.AuthenticateServiceAccount(email, securityPath);
List<String> file = GoogleHelper.GetFiles(service,
"mimeType='image/jpeg' and name contains 'aa'");
String newFile = newPath+id;
gh.DownloadFile(service, file[0],newPath);
//get File Method:
public static List<String> GetFiles(DriveService service, string search)
{
List<String> Files = new List<String>();
try
{
//List all of the files and directories for the current user.
FilesResource.ListRequest list = service.Files.List();
list.MaxResults = 1000;
if (search != null)
{
list.Q = search;
}
FileList filesFeed = list.Execute();
// MessageBox.Show(filesFeed.Items.Count);
//// Loop through until we arrive at an empty page
while (filesFeed.Items != null)
{
// Adding each item to the list.
foreach (File item in filesFeed.Items)
{
Files.Add(item.Id);
}
// We will know we are on the last page when the next page token is
// null.
// If this is the case, break.
if (filesFeed.NextPageToken == null)
{
break;
}
// Prepare the next page of results
list.PageToken = filesFeed.NextPageToken;
// Execute and process the next page request
filesFeed = list.Execute();
}
}
catch (Exception ex)
{
// In the event there is an error with the request.
Console.WriteLine(ex.Message);
MessageBox.Show(ex.Message);
}
return Files;
}
If we check the documentation Search for Files
name string contains1, =, != Name of the file.
They also show it being used
name contains 'hello' and name contains 'goodbye'
Now the file.list method returns a List of file resources. If you check file resources name is not a parameter title is.
So if you do
mimeType='image/jpeg' and (title contains 'a')
Your request will work.
Now the reason the documentation is wrong is that you are using the Google Drive v2 API and the documentation has apparently been updated for Google Drive v3 which you guessed it uses name instead of title for a file.
IMO there should be two because well its just different APIs here.
I am new to Telerik controls, in my code I am trying to Upload excel file using RadAsync upload.
Code is working fine, but when user is trying to upload a file which is already opened in the background- I am getting javascript exception.
Is there is any way by which I can alert user in case file is already opened?
You can use OnClientFileUploadFailed event of Telerik RadAsync Upload.
Something like
function OnClientFileUploadFailed(sender, args) {
var upload = $find("<%= RadUpload.ClientID %>");
var errormsg = args.get_message();
var displaymsg = new String();
sender.deleteFileInputAt(0);
if (errormsg.search("[IO.IO_SharingViolation_File]") != -1) {
displaymsg = "File: is currently in use. Please close the file and try again.";
}
else {
displaymsg = "The file you selected is currently in use. Please close the file and try again.";
}
alert(displaymsg);
args.set_handled(true);
}
I am using Telerik asp.net MVC 3 file control in my Razor view (Catalog/Product View) like this:
#(Html.Telerik().Upload()
.Name("orderImageAtachment")
.Async(async => async.Save("Save", "Catalog").AutoUpload(true))
.ClientEvents(events => events
.OnSuccess("ItemImageOnSuccess")
.OnError("ItemImageOnError")
)
)
I have created an ActionResult like this:
public ActionResult Save(IEnumerable<HttpPostedFileBase> orderImageAtachment, string CompID)
{
// The Name of the Upload component is "attachments"
foreach (var file in orderImageAtachment)
{
// Some browsers send file names with full path. This needs to be stripped.
var fileName = Path.GetFileName(file.FileName);
var physicalPath = Path.Combine(Server.MapPath("~/Content/Docs"), fileName);
// The files are not actually saved in this demo
file.SaveAs(physicalPath);
}
// Return an empty string to signify success
return Content("");
}
and client side functions like this:
function onSuccess(e) {
// Array with information about the uploaded files
var files = e.files;
if (e.operation == "upload") {
alert("Successfully uploaded " + files.length + " files");
}
}
function onError(e) {
alert('Error in file upload');
// Array with information about the uploaded files
var files = e.files;
if (e.operation == "upload") {
alert("Failed to uploaded " + files.length + " files");
}
// Suppress the default error message
e.preventDefault();
}
I get select button which opens browse window. But clicking it does nothing.... I am not sure whats wrong. Do I need to add something in web.config? Please suggest.
I'm a little confused at which point its not working, but I'm assuming its not hitting the action in your controller. I'd make sure you are trying a fairly small file, the default limit is 4mb.
Also it looks like the signature of your Save Action does not match the route you are giving it in the upload's async.Save(...). I'm not sure it will matter since its a string, but you might try removing the Save actions's CompID parameter (doesn't look like its used in the snippet at least).
I'd try using fiddler or the developer tools in whichever browser you are using to see if u are getting a 404 error by chance.
I am in a rather unusual pickle. I am modifying an image uploader and I thought I had it working. It needed to:
take a file from the client and upload it to server.
If file is an image, perform resizing operations on it.
If file is an image, create a thumbnail.
What I have works great when uploading images with Internet Explorer 8. But, when I upload images using Chrome, or Firefox3.+, the image gets uploaded but steps 2 and 3 are not performed. I don't get any server errors or anything. As 2 and 3 are steps that are performed on the server I have no idea how a change in browser could effect them.
I'm not sure if it has anything to do with my checking for whether the file is an image or not. But, for the sake of being thorough, here's the code I use:
try
{
string Filename = FileSystemUtilities.CleanupFilename(Path.GetFileName(hpf.FileName));
Filename = hpf.FileName;
string FileToSave = DestDir + Path.DirectorySeparatorChar + Path.GetFileName(Filename);
hpf.SaveAs(FileToSave);
bool IsImageFileType = ImageUtilities.IsImage(Filename, imageExtensions);
// below does not seem to execute when using non ie browser
// everything is smooth sailing when using ie.
if (IsImageFileType)
{
ImageUtilities.ResizeImageIfNecessary(FileToSave, mainMaxWidth, mainMaxHeight);
ImageUtilities.CreateThumbnail(FileToSave, thumbMaxWidth, thumbMaxHeight);
}
ValidOperation++;
sb.AppendFormat("{0} uploaded successfully<br/>", Filename);
}
Any thoughts? Why would server side code behave differently based on browser?
Edit: ImageUtilities.IsImage()
public static bool IsImage(string file, string[] imageExtensions)
{
file = Path.GetFullPath(file);
if (File.Exists(file))
{
string CurrentFileExtension = Path.GetExtension(file);
return imageExtensions.Count(x => x == CurrentFileExtension) > 0 ? true : false;
}
else
{
return false; //file doesn't exist
}
}
This difference would be caused by a difference in the filename sent by the browsers.
For example, some browsers include the full path.
Your ImageUtilities.IsImage function can't handle the filename sent by non-IE browsers.
EDIT: Your function is very wrong.
Change it to
return imageExtensions.Contains(Path.GetExtension(file),
StringComparer.OrdinalIgnoreCase);