def index(blob_key): input_numbers = BlobInfo.get(blob_key).open().read().split() output_numbers = [CoinDeterminer(num) for num in input_numbers] context = {'download_path': to_path(download, blob_key=blob_key), 'input': input_numbers, 'output': output_numbers} return TemplateResponse(context, 'updown/ok.html')
def blobstore_callback(request, entry_id): info = None key_match = re.search(r"blob-key=([^;\r]+)[;\r]", request.body) if key_match: info = BlobInfo.get(key_match.group(1).strip('"')) if not info: return render(request, "upload.html", {'err': True}) logging.info("Received file: %r" % ((info.filename, info.content_type, info.size, info.key()),)) def tx(entry_id): entry = GalleryEntry.get_by_id(int(entry_id)) if not entry: return render(request, "upload.html", {'err': True}) if not entry.photos: entry.photos = [info.key()] # also publish the entry entry.tags = list(set(entry.tags + ['public'])) else: entry.photos = entry.photos + [info.key()] entry.put() logging.debug("Updated %r" % entry.key) return http.HttpResponseRedirect("%s?%s" % (reverse(single, args=[entry.key.id()]), urlencode({'ty': ''}))) return ndb.transaction(lambda: tx(int(entry_id)))
def _move_shop_loyalty_app_to_cloudstorage(la_key): la = db.get(la_key) if not la.package: return blob_info = BlobInfo.get(la.package.key()) filename = '%s/oca/launcher/apps/%s.apk' % (ROGERTHAT_ATTACHMENTS_BUCKET, la.app_id) with cloudstorage.open(filename, 'w', blob_info.content_type) as f: blob_reader = blob_info.open() f.write(blob_reader.read())
file_name = self.request.get('file') size = self.request.get('size') if file_name is not None and len(file_name) > 0: query = BlobInfo.gql("WHERE filename = '%s'" % file_name) blob_info = query[0] self.response.headers['Content-Type'] = "application/json" self.response.out.write(json.dumps(blob_info, default=serialize)) elif size is not None and len(size) > 0: query = BlobInfo.gql("WHERE size > %s" % size) data = [] for result in query: data.append(result) self.response.headers['Content-Type'] = "application/json" self.response.out.write(json.dumps(data, default=serialize)) else: blob_info = BlobInfo.get(key) if blob_info is not None: self.response.headers['Content-Type'] = "application/json" self.response.out.write(json.dumps(blob_info, default=serialize)) else: self.response.set_status(404) def delete(self): key = self.request.get('key') async = self.request.get('async') if async is not None and async == 'true': delete_rpc = blobstore.delete_async(key) if delete_rpc.get_result() is None: self.response.out.write(json.dumps({ 'success' : True })) else: self.response.out.write(json.dumps({ 'success' : False }))
file_name = self.request.get('file') size = self.request.get('size') if file_name is not None and len(file_name) > 0: query = BlobInfo.gql("WHERE filename = '%s'" % file_name) blob_info = query[0] self.response.headers['Content-Type'] = "application/json" self.response.out.write(json.dumps(blob_info, default=serialize)) elif size is not None and len(size) > 0: query = BlobInfo.gql("WHERE size > %s" % size) data = [] for result in query: data.append(result) self.response.headers['Content-Type'] = "application/json" self.response.out.write(json.dumps(data, default=serialize)) else: blob_info = BlobInfo.get(key) if blob_info is not None: self.response.headers['Content-Type'] = "application/json" self.response.out.write(json.dumps(blob_info, default=serialize)) else: self.response.set_status(404) def delete(self): key = self.request.get('key') async = self.request.get('async') if async is not None and async == 'true': delete_rpc = blobstore.delete_async(key) if delete_rpc.get_result() is None: self.response.out.write(json.dumps({ 'success' : True })) else: self.response.out.write(json.dumps({ 'success' : False }))