def upload_mediakit(): mediakits = Mediakit.all() form = MediakitForm() if form.validate_on_submit(): if request.method == 'POST' and 'mediaurl' in request.files: file = request.files['mediaurl'] filedata = file.read() filename = file.filename ext = file.filename.rsplit('.', 1)[1] content_type = file.content_type mediakit = Mediakit( key_name= request.form['mediakit_category'], mediakit_category = request.form['mediakit_category'], medianame = filename, mediaurl = db.Blob(filedata), ext = ext, content_type = content_type ) try: mediakit.put() mediakit_id = mediakit.key().id() flash(u'Mediakit is successfully saved.', 'success') return redirect(url_for('upload_mediakit')) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return redirect(url_for('upload_mediakit')) return render_template('list_media_kits.html', mediakits=mediakits, form=form)
def get_file(category_id): """k = db.Key.from_path('MediaKit', category_id)""" mediakit = Mediakit.get_by_key_name(category_id) return app.response_class(mediakit.mediaurl,mimetype=mediakit.content_type,direct_passthrough=False)