How to save a file with the same name to Google Cloud Storage
1 answer
One thing you can do is add a timestamp to your file name on upload
eg.
$date = new DateTime();
$timeStamp = $date->getTimestamp();
$fileName = $fileName. "_" . $timeStamp;
And then when you allow the user to upload the file, read the filename and remove the last part from the underscore and give the link to the user with that parameter in the url with the original final name
$service = new Google_Service_Storage($client);
$objects = $service->objects->listObjects($bucketName);
// Assuming first item you are downloading
$objects = $objects['modelData']["items"][0];
$filename = substr($objects["name"], 0, strrchr($objects["name"],"_"));
$url .= "&response-content-disposition=attachment;%20filename=.$filename"
+3
user4045204
source
to share