Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class StartTransGsToBsHandler(webapp2.RequestHandler):
- def get(self):
- the_date = date.today()
- self.response.out.write('<html><body>')
- self.response.out.write('<form action="" method="POST" >')
- self.response.out.write("""start transfer from google storage to blobstore<br>
- <label for="id_filename">filename</label>
- <input type="text" id="id_filename" name="filename" value=""><br>
- <label for="id_storage_path">storage path</label>
- <input type="text" id="id_storage_path" name="storage_path" value="/gs/">
- <input type="submit" name="submit" value="Submit"> </form></body></html>""")
- def post(self):
- filename = self.request.POST.get('filename')
- storage_path = self.request.POST.get('storage_path')
- taskqueue.add(url='/admin/gs_to_bs', countdown=0, params={
- 'filename': filename,'storage_path':storage_path})
- self.response.out.write('hi')
- class TransferGsToBsHandler(webapp2.RequestHandler):
- def post(self):
- filename = self.request.POST.get('filename')
- storage_path = self.request.POST.get('storage_path')
- readsize = 5000000 #5MB
- # Create the file
- file_name = files.blobstore.create(mime_type='application/octet-stream',
- _blobinfo_uploaded_filename=filename)
- #open gs file
- # Open the file and write to it
- outf = files.open(file_name, 'a')
- logging.info("transfering file %s"%filename)
- inf = files.open(storage_path,'r')
- data = inf.read(readsize)
- inf_pos = inf.tell()
- while data != "":
- outf.write(data)
- logging.info("reading...%s"%inf_pos)
- inf.close()
- inf = files.open(storage_path,'r')
- inf.seek(inf_pos)
- data = inf.read(readsize)
- inf_pos = inf.tell()
- outf.close()
- outf = files.open(file_name, 'a')
- inf.close()
- outf.close()
- logging.info("done")
- # Finalize the file. Do this before attempting to read it.
- files.finalize(file_name)
- # Get the file's blob key
- blob_key = files.blobstore.get_blob_key(file_name)
Add Comment
Please, Sign In to add comment