I'm using GAE version 1.9.0 and I want to delete an image from the data storage and upload another image to its location. This is how I'm doing it right now.
unlink("gs://my_storage/images/test.jpg");
move_uploaded_file($_FILES['image']['tmp_name'],'gs://my_storage/images/test.jpg');
And then I want to get the Image serving URL of the latest uploaded image, and I do it like this.
$image_link = CloudStorageTools::getImageServingUrl("gs://my_storage/images/test.jpg");
The issue is, when the name of the deleted image("test.jpg") and the uploaded image("test.jpg") is the same, the old file is served when I call for the newly uploaded file(I think it is cached.)
Is there anyway I can permanently delete this file without caching it?
You should probably delete the original serving URL before creating another with the same name.
There's a deleteImageServingUrl() method in CloudStorageTools that you can use to do this.
Here it is how to do in php laravel.
$object = $post_media->media_cloud;
$objectname = substr($object,48,100);
$bucket = Storage::disk('gcs')->delete($objectname);
Here in $object i get google cloud image url from db
Then we take only object name from that url, by substr.
Since you have given in your config Storage class as Storage::disk('gcs')
so this will call the function delete by taking the objectname.
Hope it helps anyone.
Note : For multiple images either pass an array of objects, or repeat it foreach loop.
Related
I actually want to upload an image to a server.
To achieve this, i want the user just paste the image into chrome (the image is a print screen in fact), and then i post the stream to a php page, convert the stream as an image, and then upload it.
How can i achieve this web application ?
Today i have develop some differents parts :
I used this script, and i create the Upload.php page which gets the post variable and try to Create and image.
The problem i have, is that when i post the data, i only get a blob. I would like to get a base64 stream.
Can you help me ?
Thanks in advance.
I'm not sure why you are specifically looking for a "base 64 stream". If you are sending the Blob to your server via ajax, as far as your server is concerned, it's a file. Treat it no different than any other upload server-side. A Blob is a File without a name property. That's perhaps a bit overly-simplistic, but my point is that, again, this is really nothing more than a file as far as your server knows.
Assuming you are sending a multipart-encoded request, I'd like to point out that most user agents will set the filename property of the item's Content-Disposition header in the request to "blob" when the item you are uploading is a Blob instead of a file. It is possible to change this value in some browsers via the 3rd argument in FormData's append method, but I wouldn't rely on this just yet.
Also note that, if you are interested in a library that handles all of this already, I maintain, Fine Uploader which natively supports uploading images via paste in Chrome.
To answer this old question: Posting an image from clipboard with chrome is pretty much the same as posting a dropped file - except that the image/blob doesn't have the properties "name" and "lastModified".
var entry = items[i].webkitGetAsEntry();
if (!entry) entry = items[i].getAsFile();
if (entry instanceof Blob) /** CHROME pastet Bilder als Blob **/
{
entry.isFile = true;
entry.lastModifiedDate = new Date();
entry.name = ""+new Date().getTime()+"."+entry.type.split('/')[1];
}
if (entry.isFile)
{
//handle dropped file
}
I am doing products import php script for prestashop 1.3.1 and I have one problem. I have URL of picture, but i dont know hoe to use it and make different images (thumbnails it is called I think).
If I have picture http://www.nordix.cz/img/p/824-2268.jpg what I must write in PHP to make thubnails?
Thank you so much for tips!
To process an image (create thumbs) first you have to copy it to a local directory. You can't do any processing on an image which is on another server or url. So here is how i did it in one of my PS project.
1) First check if the image exists or not. You can do it by using fopen in read mode, if it returns true, then the file exists. It is a good practice to do it because it will avoid unnecessary calls to the remote server.
$imageUrl = "http://www.nordix.cz/img/p/824-2268.jpg";
#fopen($imageUrl, "r");
2) Now you have the image as the fopen returned true, you need to copy the image to the PS temp directory as below
$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS');
copy($imageUrl , $tmpName);
after the copy function downloads the image to PS temp directory, then you can process that image as you want. Remember that you have to make all processing on $tempName, as it is the file now. $tempName is like $_FILES['imageFieldName']['tmp_name'].
Thank you
Prestashop provides a set of function to process images. I've never worked on 1.3 but in 1.4 they are located in /images.inc.php (they made a class in 1.5). Take a look at this file and you will find all the function you will need, especially imageResize()
I have created a custom product configurator that saves a canvas element as a base64 encoded image. When I echo the image in the browser as the image src it works fine.
So something like this works:
$base64Image = $_POST['dataUrl'];
echo '<img src="'.$base64Image.'" />';
My problem is that codeigniter wont add this base64 image src to the session, probably because its too big. I have tried some methods that people have used to write an image to the server and they all throw errors. Does anyone know how I can write this base64 string to an image on the server like 'myimage.png' in the images/custom folder?
Any help is appreciated.
You can also use
$decoded=base64_decode($base64Image);
file_put_contents('newImage.JPG',$decoded);
Reference Link: http://j-query.blogspot.in/2011/02/save-base64-encoded-canvas-image-to-png.html
Use tempnam() to get a unique file name in a directory writable by the script. You can map a session variable "thisUsersTempFile" to that file name.
Or you can store the association somewhere else if it is not temporary. If you need to clean up the tmp files, you would probably need to do that since I don't think you can hook the session destruction. You could poll for existing sessions and delete the tmpfiles associated with the sessions that were destroyed. You could use a cron job for that.
I'm writing a web app that at one point allows a user to upload a photo to a flickr account (mine). I want to do this without saving the intermediate image on the server my web app is on.
What I've got so far is a page which implements phpFlickr and accepts a POST from a simple html form. I use $_FILES['file']['tmp_name'] as the path for phpFlickr to use. Here's the code:
<?php
require_once("phpFlickr.php");
$f = new phpFlickr("apikey", "secret", true);
$_SESSION['phpFlickr_auth_redirect'] = "post_upload.php";
$myPerms = $f->auth("write");
$token = $f->auth_checkToken();
$phid = $f->sync_upload($_FILES['file']['tmp_name']);
echo "Uploading Photo..." . $phid;
?>
I'm guessing that the tmp file is being lost because of the redirect that happens when $f->auth("write") is called, but I don't know. Is there a way to preserve it? Is there any way to do this without saving the file to the server?
Answer: There is No way to directly upload a file to Flickr without saving it as an intermediate file.
I've moved on to using move_uploaded_file() followed by a flickr API call, and its working perfectly.
I've also managed to get it to play nice with the excellent Jquery Uploadify, which lets me send multiple files to it in one go.
I am working with the FaceBook API to upload photos, and the API requires a local file path. As far as I can tell they are handing the request off to CURL like such: upload=#localfilename
But my files don't reside locally, so I am trying to figure out if there is a way to make it work with a remote file....
I tried pointing it to a local file which just did 'echo file_get_contents('some_remote_image.jpg');'
but that didn't work.
Does anyone have any ideas?
Thanks!
You can however link to them eg
<img src="www.mydomain.com"/>
Is it not possible to cache the file on your server and then delete it after upload? I wrote a Flickr -> Facebook Photo Album app that does this very thing.
All right, well if you don't want to do that, you can do this:
Edit the file facebookapi_php5_restlib.php, tracing the photo upload calls down to the actual curl call, which is in:
private function post_upload_request($method, $params, $file, $server_addr = null)
Now the hacky part, instead of passing the filename for $file, pass in an array and then check if its an array in this function. If it is, extract the binary data from it and set it as one of the post parameters. Some curl parameters that you may need can be found here:
http://www.digimantra.com/technology/php/post-pictures-on-twitpic-api-using-php/