0

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?

4
  • 2
    I think this is a caching problem. See this answer: stackoverflow.com/questions/13996116/… Commented Jun 13, 2014 at 6:06
  • Thanks for the reply Peter, but if the cache is disabled, that would be a problem right? Like it would take alot of time to load the image. Is there a way to delete the image and the cache, so the cache will be served untill the image is deleted? Commented Jun 13, 2014 at 6:11
  • Did you clear your own browser cache? Commented Jun 13, 2014 at 7:04
  • Yes. That was the first thing I did. Commented Jun 13, 2014 at 7:51

2 Answers 2

2

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.

0

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);
  1. Here in $object i get google cloud image url from db
  2. Then we take only object name from that url, by substr.
  3. 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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.