POST request with image from iPad/iPhone - javascript

I try to POST images to server.
I have finished it successfully like this:
I have webView, catch "right" url and switch viewControllers.
After switch them I choose image from PhotoLibrary or from camera, POST it and switch controllers back.
P.S. As u know, in mobile safary(in webview too) all "choose" buttons on sites are disabled.
I think that it isn't straightforward way, so..
My question:
Can I choose images from webview's button "choose"? I want to choose images on iDevices similar PC without another viewControllers.
I'm newbie in programming, but I have some ideas(don't know how to realize them):
1.Upload image to DOM. And use "save" button on webView.
2.Add button with selector(can I?) to webView with Javascript. And handle this selector.(smth like that) I saw similar thing for toolbar item.

Get the image. Convert in to a base64 string (http://stackoverflow.com/questions/3889478/uiimage-to-base64-string-encoding)
Put this string inside the value of a hidden input.
Submit the form.
On the server convert the base64 back to binary and save to file/DB.
(PS. File inputs are not supported in iOS safari. The choose button is just there as a placeholder, to not break any layouts. There is absolutely no code behind the element, so there is no way try to get it to work.)

Related

How can I save the content of tinyMCE before destruction? (close tab, navigate etc.)

We have a webpage which has a tinyMCE editor tied to a DB. In this webpage we have some buttons like „Help”, „Settings”, „Logout” which can 'erase' (let's use this terminology) the content of our tinyMCE editor, because these buttons open another layout(s) in which, of course, the editor is absent.
We want to trigger our „Save to Db” subsystem when the user:
Clicks anyone of buttons which destroy the editor (see above)
Destroy the tinyMCE editor by closing the tab / browser.
Destroy the tinyMCE editor by navigating somewhere else (eg. from ourSite.com to google.com)
Now we tested all the above and (of course) the content isn't saved.
How can we achieve this automatic save on destroy?
The solution must work on Chrome/Edge, Firefox and Safari.
Notes:
we tried this demo: https://fiddle.tiny.cloud/hRhaab/2 (hooking the „remove” event) but it doesn't seem to work.
an alternative popup with „The data is not saved. Do you want to continue?” is also acceptable.
the data is rather small. No images, just some text (few A4 pages at most).
in the case of buttons, we try to avoid the obvious solution by writting a DoSaveMyEditor() under each button
Any help?
You can utilize the TinyMCE Autosave plugin. It does the job by itself but saves the data to local storage. However, it can be identified by setting an autosave_prefix and then taken out of the storage and uploaded to your DB.

How to reload base64 animated GIF?

I use base64 animated GIF on my web page, when I try to reload page GIF still show last frame. How can I reload GIF from its beginning?
I tried use JS to clear innerHTML and then assign it back to my base64 GIF, but nothing happened.
I am also using C# and CefSharp (tried use Refresh() and chromeBrowser.GetBrowser().Reload()), would be great to get any tips how to make GIF play from its beginnig.
I use base64 because I cannot store image on users hard drive or Web, but I need to put this image into HTML, which can be loaded by CefSharp using C#. If there are any other ways to use animated image in HTML without storing it on HDD or web, please give me some tips too.
Update:
I decided to leave base64 because big size of my gifs (>25 Mb) cause lags and problems with reload.
I use CEFSharp v55-pre01 and found new problem.
What do I have:
Main menu
Form 1 (with cefsharp browser, which loads gif by code automatically)
Form 2 (with cefsharp browser, loads same gif)
From main menu I call Form 1, when Form 1 initialize, Form 1 create hidden Form 2.
First form initialize Cef
if (!Cef.IsInitialized)
{
Cef.Initialize(settings);
}
Each form in constructor initialize own browser
chromeBrowser = new ChromiumWebBrowser("");
Controls.Add(chromeBrowser);
Problem appear in situation, when I close second form (no mater is 2nd form shown or not) and dispose both forms and call Cef.Shutdown(). When I try open back first form from menu my app crashes.
Error appear at second form constructor on line chromeBrowser = new ChromiumWebBrowser(""); with such text:
An unhandled exception of type 'System.AccessViolationException'
occurred in CefSharp.Core.dll
Additional information: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.

Is it possible to serve up a different file than the intended one to be downloaded via JavaScript?

At work they want to do this to prevent people from downloading images easily from our site. They won't go the disable right click option, so they want to do what Flickr is doing:
http://www.flickr.com/photos/scg/12332332454/sizes/l/
If you right click and try to download that image it downloads the entire html page instead. Can this be done via JS or is it something handled by the server?
I know all this goes against usability and doesn't actually prevent people from ripping off images but it's what the ticket I'm assigned asks for.

how to restrict user to save images from site not by disabling right click

how to restrict user to save images from site not by disabling right click.
I tried disabling right click but it is causing problem for image with link, as we unable to right click on that image to open a lick in a new tab.
Any other good solution or advise??
If the end user can see the image, it's already on his system. Saving it to a system or copying it to the clipboard is trivial and cannot be disabled in any reliable way.
If you want to keep control over the image, don't put it on the internet.
Watermarking is the best solutionyou can do.
Whatever your solution, in the end user can take a screen shot anyway.
Make use of images with water mark of your site.
If a user can see the image on screen you can not restrict the user form saving the image.
1) user can use print screen option.
2)user can save the page with complete html option.this way she/he will get image.
3)user can take the snapshot of image if it is visible in forntend to the user.
You can try to serve images with your logo or string identifying your property so that it renders the image useless unless they are OK using it as is. However you can't prevent the saving of what is served. Another option is to serve only thumbnails or lower quality version of it.
Stay away from disabling normal user actions, like right-click disabling.

Can I programmatically save part of a web page as an image?

If possible, I would like to do this with a simple button. The users are not terribly comfortable with computers, which is why I haven't just told them to print screen or use the snipping tool.
I know it can be done in Mozilla-based browsers with <canvas> and drawWindow(). But this application is running on Internet Explorer 7 and 8.
The page shows some graphs (generated by a ReportViewer control) based on the input of a couple of dropdowns. Does that mean a client-side script is the only option? Or could I do it in the ASP.NET back end somehow? Perhaps re-generating an image any time the dropdowns are changed?
(I've been a desktop dev for so long that I don't quite "get" what you can and can't do in web apps yet.)
From what I understand you've got some drop downs and you're generating a graph based on the input of those drop downs by the user?
So if I was doing this with PHP (just trying to give you ideas here, dunno whats possible and what's not in ASP) I would create an image magic or gdb library script that builds a jpeg based on the variables input in a querystring.
For instance this would output a jpeg image of a simple graph with 3 points on it:
http://mydomain.org/image.php?value1=10&value2=20&value3=30
Then for the front end of my script I would probably use jquery/ajax to call that script and show the image as the user is changing the values.
Then you have an image that you can potentially force download or instruct users to right click and choose "save as".
Anyway, this is just an idea, not a solution. I don't know about ASP.NET, but this is how I would do it in PHP.

Categories