Google App Engine PHP Serving Images from Google Cloud Storage - php

In my app, I want users to be able to upload a picture to set for their profile. I only want them to be able to have one picture set and in storage (Google Cloud Storage) at a time.
When users upload the picture, it gets renamed the same thing every time. I do this so I don't have to search and delete the old file. The new file just replaces it.
The problem I'm running into is that once an image is uploaded and replaces the old image, it remains the old image even though the actual file in Google Cloud Storage has changed to the new image. I have verified the file has been successfully replaced by looking at the actual file in the storage browser. There is no trace of the old file.
To serve the image I am using this method:
https://developers.google.com/appengine/docs/php/googlestorage/images
getImageServingUrl() should be pulling the correct file as it is named exactly the same, but it's not. How is it still hanging on to the old image? Is the old file being cached or something?
The result of getImageServingUrl() is being echoed into the src attribute of an img tag.
Any insight would be appreciated! Thanks!
Update: I tried calling deleteImageServingUrl() before getImageServingUrl(), however the problem still persists.

Related

Convert Uploaded S3 Images to Original File Path

I attempted to move over our local WordPress images to S3 using the WP Offload S3 plugin and it turns out because the Object Versioning option was turned on, it added numbered folders for each image in the path, i.e:
[…]xxx.s3-us-west-1.amazonaws.com/wp-content/uploads/2018/04/xxxxxxxx/example.jpg
[…]xxx.s3-us-west-1.amazonaws.com/wp-content/uploads/2018/04/xxxxxxxx/example-123×456.jng
The original path was previously:
[…]xxx.com/wp-content/uploads/2018/04/example.jpg
[…]xxx.com/wp-content/uploads/2018/04/example-123×456.jng
If I delete the WP Offload S3 plugin and then reinstall it, it seems like the plugin's settings are still saved and the media still points to the Amazon S3 link, probably saved somewhere in the SQL database.
Is there a simple PHP script to convert the object-versioned file paths back to the original path on all of the already uploaded media?
I don't know much about coding, but perhaps something like this might be of reference? https://gist.github.com/TJNevis/8df059e8ba6d9cf28a01#file-s3fixexistingmedia-php-L27

Google Cloud Storage: how to update cached versions of files?

I have uploaded thousands of files. However, when a user rotates an image in my website I internally update the uploaded version (re-upload the rotated version via PHP to the bucket). But, google keeps displaying the same image again and again.
However, if I append ?r=[number]
Where [number] is some random number, the updated image is displayed correctly. And if I then remove the ?r=[number] part from the URL the old image is displayed again.
Is there a way to tell google to update the displayed version?
You can set the cache-control header to private for the uploaded files to ensure that the image is always served fresh, or set the max-age to whatever your maximum bound for staleness is. See Cache Control in the Google Cloud Storage documentation for details.
Note that after you do this, you'll still need to wait for browser caches containing the original objects expire, but all new images served will use the updated cache control settings.

WPMU moved, only featured images have bad path

I recently moved a multi site wordpress installation to another development server. I did this by exporting the DB to SQL, importing it on the new server, changing the wp-config DB login data and DOMAIN_CURRENT_SITE to localhost and running the search and replace script to update the server address (was some IP, now is localhost). Everything seems to work fine now, except for featured images of pages. They are not displayed.
The problem seems to affect only sub-sites and not the main site. The main site, however, stores its uploads (featured images are among them) in wp-content/uploads, whereas the other sites store these in wp-content/blogs.dir. I did not change the files in there, of course and don't understand why the images don't display. All the other images do.
When I see the broken path of the image, it looks like this:
http://localhost/cze/files/2012/11/profile.jpg
which is strange, becouse the image is on the specified path, I just checked. I'm really puzzled.
For the record, uploading new images is fine and when these are uploaded and used as new featured images, it works fine. I would however like to avoid having to go through all the sites and changing all the featured images.
I have not edited anything else (.htaccess for example).
Any ideas on what could be causing this?
Thanks,
Ondrej
I am sure there are still some old URLs in the database. Please make sure you replaced the home, site_url and fileupload_url like codex mentioned: http://codex.wordpress.org/Moving_WordPress#Moving_WordPress_Multisite
Also, open the mysql file in a text editor and look for the old url using find option. Do you see any?

Best way to upload images to another server in php

I need to upload an image to another server once it's been submitted by a user. I have 3 ways to accomplish it.
Upload the image to the primary server and then upload it to another server via ftp.
Upload the image to the primary server and store it somewhere in the temp folder. Then, run a cron script to upload images from the temp folder to another server.
Have a php script which would accept images uploaded directly to another server.
Please note, I need to store image references and some metadata in the primary server database. So, by keeping that in mind makes me automatically drop the 3rd choice from the list. Since, it's hard to get the uploaded image file name from another server once it's there.
The first one, is a good one since I can generate the file name before I upload it to another server and once it's there I can easily save the required data into the database. The obvious drawback here is that this requires extra patience for the user while the image is being uploaded first to the primary server, then to another server.
The second method seems the best one for me, since the image will be uploaded to another server unnoticeable for users. The only thing bothers me is that the url for the uploaded image will be changed once the cron uploads the image to another server. Not sure what side effects might come up later because of this.
Has anybody done something similar before? If yes, please share your experience with me.
Thanks a lot!

Download JPEG files in batch mode keeping the path

I wish to download a lot of jpegs keeping the original name and their paths.
Example: http://www.somesite.org/path1/image1.jpg, should be downloaded on www.mysite.com/path1/image1.jpg (and creating the "path1" directory if it does not exist) This is repeated a lot of times, fetching the original download site from a field on a database.
Is it possible? Keep in mind that I can't use cURL nor wget since I am on a "limited" hosting service.
Well, first of all you have to find a method to get all download links. There are several ways to fetch data from a database, depending on what database it is (mysql, exel, textfile...)
Then you need to use ftp to upload these files into your database. Strip down the original link to the path (remove the www.somesite.org) and use your site + the path for storing.
This is very manageable, but we are not here to do all the thinking for you. Use google and try methods first, then come back if you are facing a specific problem.

Categories