Hey folks, I'm learning the new Cloud Storage and question how to I migrate 
my app with a least friction.

Now I'm using this sample piece of code to save images:

from google.appengine.api import images, files


def upload(ext, stream):

    file_name = files.blobstore.create(mime_type=mimetypes.types_map[ext])


    with files.open(file_name, 'a') as f:

        f.write(stream.getvalue())


    files.finalize(file_name)

    return images.get_serving_url(files.blobstore.get_blob_key(file_name))


Which I'm thinking to change to the next:


def upload(ext, stream):

    filename = "/images/my_file"

    with gcs.open(filename, 'w') as f:

        f.write(stream.getvalue())


    # Blobstore API requires extra /gs to distinguish against blobstore 
files.

    blobstore_filename = '/gs' + filename

    # This blob_key works with blobstore APIs that do not expect a

    # corresponding BlobInfo in datastore.

    blob_key = blobstore.create_gs_key(blobstore_filename)

    return images.get_serving_url(blob_key)


Which seems to work.

The problem that in the old version I don't have to worry about filenames, 
Files API job was to assign me one. Now I need to give a name myself. Any 
way the new api should do it for me? Or maybe I should just hash the file. 


-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/145ce87c-e299-4d7f-8c8c-83f2959b5548%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to