简体   繁体   中英

Google Cloud Storage uploaded unreadable filesnames (php)

After some problems i could finally upload files with google app engine to my bucket, but now the name of the uploaded file is unreadable, like a temp name, encrypted or something, like this:

L2FwcGhvc3RpbmdfcHJvZC9ibG9icy9BRW5CMlVvQWFjdkRYbWhtY1dPRGc2ZjlkVzRUU0lOV0FFMThWZnAxbUl1MzFVUndLSWdYVTBvdHhyYXl4UWdNOElXWklvX2hkQjdfaHYxbWNvc0dlSEtSQ184enJCU3M4QS5PTW5KWVBiTWdWZTJGdmQ4

How can i give the name that i want to an uploaded file???

I'm using the same code as the one given in the google developers documentation, like this:

require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;

$options = [ 'gs_bucket_name' => 'my_bucket' ];
$upload_url = CloudStorageTools::createUploadUrl('/upload_handler.php', $options);


<form action="<?php echo $upload_url?>" enctype="multipart/form-data" method="post">
    Files to upload: <br>
   <input type="file" name="uploaded_files" size="40">
   <input type="submit" value="Send">
</form>

Does anybody know if Amazon's S3 is easier and more standard friendly? Also if it's posible to comunicate with GAP, I think i read that it is posible, but now i'm not sure about anything, too late and my brain is burnt :(

Thanks in advance!!

I made it work, it was easy, i just missunderstood something...

It must be done in upload_handler.php, is obvious but...xD. And as Mars says with move_uploaded_file, or with rename. Something like this (maybe is usefull for someone):

$gs_tmpName = $_FILES["myfile"]['tmp_name'];
$ext = strrchr($gs_name, ".");
$desired_name = "<desired_name>$ext";
$desired_name = mb_convert_encoding($desired_name, "UTF-8", "AUTO");
$desired_name = urlencode($desired_name);
$options = array('gs'=>array('acl'=>'public-read','Content-Type' => $_FILES['myfile']['type']));
$ctx = stream_context_create($options);
rename($gs_tmpName, "gs://<bucket_name>/".$desired_name, $ctx);
$publicUrl = CloudStorageTools::getPublicUrl('gs://<bucket_name>/'.$desired_name , true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM