You should store the GCS file name and just use 
cloudstorage.delete('/bucket/object_name') 
<https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions#delete>.
 
GCS functions can only work with GCS file names. I'm not what you mean by 
'only save the url in the data block user to show the photo' though, so if 
you could expand on this or provide some code it would be helpful (eg. do 
you mean the upload URL, or are you also using Images API to create a 
serving URL?)

On a side note, you can now access the Blobstore viewer from the new 
production console under 'Compute' -> 'App Engine' -> 'Blobstore'. It looks 
like this was added as the old console is about to be turned down. This 
will only show objects uploaded directly to the Blobstore though and not 
files in GCS. For these you still need to access 'Storage' -> 'Storage'.

On Monday, April 25, 2016 at 6:32:26 AM UTC-4, Juan Antonio Fernández 
Sánchez wrote:
>
> Thanks for all info, Adam,
>
> I'm using now the Cloud Storage service to upload images files. And  I 
> only save the url in the data block user to show the photo. But now I want 
> can delete the image of user using the url that I have. In dev-server I can 
> do this extracting the key of file from the url but i dont know how do this 
> in the Cloud Storage. Maybe I should save the name of file beside the url, 
> and when I need erase the photo, I use the name of file instead of the url 
> only. 
> What do you think about?
>
> El lunes, 18 de abril de 2016, 23:15:28 (UTC+2), Adam (Cloud Platform 
> Support) escribió:
>>
>> No problem. Yes, the development server stores blobs and GCS files in the 
>> same temporary directory on your machine, and both are visible in the 
>> Blobstore Viewer from the dev server admin console. This is somewhat 
>> confusing, because in the production console there is no Blobstore Viewer, 
>> only the Cloud Storage browser, 
>> <https://console.cloud.google.com/storage/browser> and anything that is 
>> only written to the Blobstore is not visible.
>>
>> I will add that there is exactly one way to get the GCS filename of an 
>> uploaded blob, but it can only be done inside the handler that you pass to 
>> blobstore.create_upload_url() 
>> <https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.ext.blobstore.blobstore#google.appengine.ext.blobstore.blobstore.parse_file_info>,
>>  
>> using blobstore.parse_file_info() 
>> <https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.ext.blobstore.blobstore#google.appengine.ext.blobstore.blobstore.create_upload_url>.The
>>  
>> FileInfo 
>> <https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.ext.blobstore.blobstore#google.appengine.ext.blobstore.blobstore.FileInfo>
>>  
>> object returned contains a field 'gs_object_name' which is the name of the 
>> file written to GCS, or None if it was only written to the Blobstore. 
>> There's a full example 
>> <https://github.com/jeremydw/gae-gcs-file-upload-sample/blob/master/main.py> 
>> which demonstrates how this works which has been uploaded by a user on 
>> GitHub. 
>>
>> On Monday, April 18, 2016 at 4:46:15 AM UTC-4, Juan Antonio Fernández 
>> Sánchez wrote:
>>>
>>> Hi Adam, 
>>>
>>> Maybe I'm confusing the options of store data on the Google 
>>> Infrastructure. 
>>> I want store the profile photos to my users in my GAE app, and finding 
>>> way to do this I found Google Cloud Storage, using the library cloudstorage 
>>> for python but also saw blobstore and gcloud and I'm a bit confusing.
>>> When I loaded a photo with gcs.open I can see this in the dev server in 
>>> the section BlobStore Viewer, because of this I thought that blobstore and 
>>> GCS is more or less the same thing.
>>>
>>> When, when I make this:
>>>
>>> gcs_file = gcs.open(filename, 'w', ...)        
>>> gcs_file.write(datos)        
>>> gcs_file.close()
>>>
>>> After I can see in Blobstore Viewer in dev_server web console a new 
>>> file, and If I use this code:
>>>         
>>>         blobstore_filename = '/gs' + filename
>>>         key = blobstore.create_gs_key(blobstore_filename)
>>>         return get_serving_url(key)
>>>
>>> I can get the url where the image is stored to use to show it wherever i 
>>> want.
>>>
>>> For this reason, I thought that was easy way to obtain from url that I 
>>> have the way to erase que photo or the file that this url refers.
>>>
>>> Thanks you very much for all your help Adam.
>>>
>>> El domingo, 17 de abril de 2016, 0:56:34 (UTC+2), Adam (Cloud Platform 
>>> Support) escribió:
>>>>
>>>> First off, Google Cloud Storage is not Blobstore. You can create a key 
>>>> for use with Blobstore with blobstore.create_gs_key(), but you should only 
>>>> do this if you really need to use Blobstore API for something (eg. with 
>>>> the 
>>>> Images API). You should not treat Blobstore and GCS as the same thing or 
>>>> intermingle them needlessly.
>>>>
>>>> So adding to that, GCS doesn't understand or care about blob keys 
>>>> <https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions>,
>>>>  
>>>> so gcs.delete(key) won't work. Objects that are uploaded to Blobstore 
>>>> don't 
>>>> necessarily exist in GCS, so there isn't a way to get a GCS file name from 
>>>> a blob key*. You need to use the GCS file path directly, eg. 
>>>> gcs.delete('/mybucket/path/to/myobject').
>>>>
>>>> So to avoid this type of problem you should always use 'cloudstorage' 
>>>> and deal with objects in terms of GCS files, using 
>>>> blobstore.create_gs_key() only when you need to use some function that 
>>>> needs the Blobstore API. You can make Blobstore talk to GCS, but not the 
>>>> other way around.
>>>>
>>>> ** The filename you get from BlobInfo 
>>>> <https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.ext.blobstore.blobstore#google.appengine.ext.blobstore.blobstore.BlobInfo>
>>>>  
>>>> is the filename from the user's machine when they uploaded the blob, not 
>>>> the filename in GCS.*
>>>>
>>>> On Saturday, April 16, 2016 at 5:22:07 PM UTC-4, Juan Antonio Fernández 
>>>> Sánchez wrote:
>>>>>
>>>>> I'm saving images in cloudstore (blobstore) using 'cloudstorage' 
>>>>> library in python. 
>>>>>
>>>>> Well, this images are the image profile from  users and I get the url 
>>>>> from blobstore to save this with the rest of data of user.
>>>>> And now I' m trying develop the way to erase this files using the same 
>>>>> url that I have saved in the data block of users, but I dont find a 
>>>>> simple 
>>>>> way to do this with the 'cloudstorage' library.
>>>>>
>>>>> I could save the filename of the photos of users in DB togheter to url 
>>>>> to access faster, but I prefer know how I can could make this.
>>>>>
>>>>> Thanks you so much for help.
>>>>>
>>>>> Code example that I want more o less:
>>>>>
>>>>> def DeleteFile(self, url):
>>>>> key = keyFromUrl(url)
>>>>> gcs.delete(key)
>>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/8f0e5eed-43f3-4501-b7c3-c3c173c29e18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to