Phonegap remove/delete taken image - javascript

I've been following the Phonegap Camera Docs, and am uploading the ImageURI to a server successfully. However, the image that was cached when the photo was taken is still on the phone. How do I clear the cache or remove the photo after I'm done uploading the photo?

You should be able to take the picture URI and pass it to window.resolveLocalFileSystemURI and then in the success callback of this method you will get a FileEntry object which you can call the remove method on.

Related

How to load image if the image is available on AWS?

I upload image from vue, to server. The server will return the image url, but it's will process the image first, and then upload it to AWS. And the process may takes about 1 - 3 second untill the image fully uploaded to AWS
The problem is my vue already get the image url before the image fully upload, and try to load it in <img>, and an error happen, 404 not found. Because it's not fully uploaded to AWS.
Question:
How to automatically load an image as soon as the image available on AWS using best practice / clean way?
For now, I use looping, and use #error, and check every 1 second. But I think it's not clean

Amazon S3 Image not found. Have to put delay

I have a meteor app where I upload an image to S3 via a node framework called knox.
It works well but when Im getting the success response from S3 with the link to the image I also want to show it to the user like this:
$("#thumbnail").attr("src", url);
However this generates a 404 not found in the console and the image is not showing. But if I put a delay for around 5-10s it works.
setTimeout(function() {
$("#thumbnail").attr("src", url);
}, 10000);
Why do I get the URL from S3 before they are ready to show it? Is there a way I can wait until its ready before showing it to the user?
As nodejs is asynchronous (meaning that it does not wait until one request is finished before next one gets called) your url gets returned quicker than the image is uploaded, therefor you can't see the image. This could be fixed using callbacks.

Upload/download/save image to a local server from a remote server using an Image URL and PHP?

I am building a Discussion Forum as part of a bigger application I am building, the forum is just 1 section of the Application.
For my TextArea fields when posting a new Topic or a Post Reply, I have decided that nothing is as good as the PageDown Markdown Library. It is the same one that StackOverflow uses on all their sites and it works better than many of it's competitors.
The way the library ships though, I am not happy with the default Insert Image functionality. You hit the button to insert an image and it allows you to enter a URL for an Image and then it inserts the proper MarkDown syntax to show the linked image.
This just won't cut it. I need the functionality that you see on StackOverflow! Very similar anyways.
I need it to show a Dialog when you click the Insert Image button, like it does now, but instead of just an input field for a Image URL, it will have 2 filed options...
Upload image from your computer
Insert an Image URL and it will then DOWNLOAD the image from that URL and insert it into the post just as if you had uploaded it from your computer. This is important to not confuse this step. IT should not simply insert the Image linking it to the original Image URL. Instead it will take that URL and download/upload the Image to the same server that the upload from computer option does and then it will insert the NEW Image URL pointing to the newly uploaded image!
Based on some simple HTML like below for a Dialog window with a filed for my Upload from Computer functionality, which I already have working. I need to come up with some JavaScript and PHP that will download/save a remote image to my upload folder on my server when a button is clicked using only the URL that will be inside the URL text input field.
So it will need to do a few things...
Fetch and save an image file to my uploads folder using PHP when the only thing that the PHP function will receive is a URL of the image which could be on the same server or most likely a remote server.
After successfully saving/uploading an image from the URL, the PHP function will return a JSON string with the status/error and if successful then it will also return the actual URL and filename of where the new image is saved on the local server. The JavaScript/AJAX script will receive this JSON response and insert the Markdown syntax for the image into the PageDown editor.
The PHP function will need to ensure that the URL that it is trying to save/download is a valid image file and not some malicious file! Also not simply just some file of the wrong filetype like a non-image file unless we are allowing the file type.
It will be part of a module installed on many dinosaur servers so it needs to work on as many servers as possible too!
From the web
From your computer
I would be greatful of any help, tips, code snippets or anything to help with this. At this stage I really just need to build a nie PHP function that will upload images from a remote URL and also ensure that the URL passed in is a real image file or even better that it is in the allowed file types array!
A couple years ago I had started this but have now lost it and I am starting over and don't remeber much about how I went about doing it then.
The easiest way to download a file from a remote server would be to use copy (http://php.net/manual/en/function.copy.php):
copy('http://someurl.com/image.png', '/var/www/uploads/image.png');
As this function returns a bool, it is easy to determine whether the operation was successful and create a JSON response.
To verify that the file is an actual image, there is unfortunately no way that is 100% sure. It is probably enough to check the mimetype though. You can use finfo for that (http://php.net/manual/en/function.finfo-file.php):
$finfo = finfo_open(FILEINFO_MIME_TYPE);
echo finfo_file($finfo, $filename);
finfo_close($finfo);
For a gif, this would return image/gif for example. You will have to hardcode a list of all mimetypes you want to allow.

How to pass an uploaded image back to html

The setup I work on is the following: A HTML-page with a canvas element displaying a Processing JS sketch and a form that allows to pass parameters to the sketch using JS-function Processing.getInstanceById(getProcessingSketchId()).setSomeParam();, which works just fine.
The user should also be able to upload an image to the server, the name/path of which is then also handed to the sketch to do loadImage(String path). The file upload (using PHP from here) works perfectly fine as well but now here is the question:
How can I get the name of the uploaded image on the server and pass it to the Processing sketch?
If the form's action tag points to a distinct PHP-file, the site with the canvas sketch is quit (variable $destination not available) or if the form's action tag points to the site itself (being a PHP-site, checking for if(isset($_POST['formSubmitted'])) {), the sketch is restarted losing all the previously changed parameters.
I also managed to have the form submission target to an internal iframe and display the uploaded image there, but that still doesn't solve my problem.
Thanks a lot in advance for any helpful hints!
It sounds like you have the data flow worked out but are struggling because a standard form upload causes a page refresh.
I would suggest using AJAX to post the image to a specific PHP image receiver service. When the AJAX upload is complete, the javascript can then call to the server to fetch the uploaded object and manipulate it as needed without refreshing the page.

UIWebView download it's image content

I'm using high charts to draw charts in a native iOS application in a web view
the problem is when I export the chart as image, the image appears in the web view and I can't save it or download it.
in the desktop browser, when I export it, it immediately start downloading.
the exporting mechanism is provided via a JS function call, I call it from the native application using
[_webView stringByEvaluatingJavaScriptFromString:#"chart.exportChart({ type: 'image/jpeg', filename: 'chart'});"]);
I made a dig into the JS library and I found that they send a post request to there server to get the image, so I don't have a URL for the image I can download it with!!
I want to be able to save the image and pass it to my native application, any help!!
thanks in advance...
One option you have is converting your web view into an image. The following snippet does it:
UIGraphicsBeginImageContext(webview.bounds.size);
[webview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Categories

Resources