def upload(): f = request.files.get('upload') # Add more validations here extension = f.filename.split('.')[-1].lower() if extension not in ['jpg', 'png', 'jpeg']: return upload_fail(message='Kelti tiktai nuotraukų tipo failus!') print(app.config['UPLOADED_PATH']) full_path = os.path.join(app.config['UPLOADED_PATH'], f.filename) f.save(full_path) head, tail = os.path.split(app.config['UPLOADED_PATH']) if tail == 'temp': image = TemporaryImg(image_file=f.filename, image_path=full_path) elif tail == 'article-images': image = ArticleImages(image_file=f.filename, image_path=full_path, article_id=app.config['THE_POST_ID']) db.session.add(image) db.session.commit() print(" Image inserted") print(TemporaryImg.query.all()) print(ArticleImages.query.all()) url = url_for('uploaded_files', filename=f.filename) return upload_success(url=url) # return upload_success call
def upload_for_ckeditor(): f = request.files.get('upload') if not allowed_file(f.filename): return upload_fail('Image only!') f.save(os.path.join(app.config['UPLOAD_PATH'], f.filename)) url = url_for('get_file', filename=f.filename) return upload_success(url, f.filename)
def upload(): """CKEditor file upload""" error = '' url = '' #callback = request.args.get("CKEditorFuncNum") if request.method == 'POST' and 'upload' in request.files: fileobj = request.files['upload'] fname, fext = os.path.splitext(fileobj.filename) if fext.lower() not in ['.jpg', '.png']: return upload_fail('Only .jpg and .png extensions are allowed') rnd_name = '%s%s' % (Common.gen_rnd_filename(), fext) filepath = config.uploadsPath + '/' + rnd_name dirname = config.uploadsPath if not os.path.exists(dirname): try: os.makedirs(dirname) except: return upload_fail('ERROR_CREATE_DIR') elif not os.access(dirname, os.W_OK): return upload_fail('ERROR_DIR_NOT_WRITEABLE') if not error: #with open(filepath, 'w+') as destination: # for chunk in fileobj.chunks(): # destination.write(chunk) fileobj.save(filepath) url = url_for('static', filename='upload/' + rnd_name) return upload_success(url=url) else: return upload_fail(error) else: return upload_fail('post error')
def upload_image(): f = request.files.get("upload") if not allowed_file(f.filename): return upload_fail("Image only!") f.save(os.path.join(current_app.config["BLUELOG_UPLOAD_PATH"], f.filename)) url = url_for(".get_image", filename=f.filename) return upload_success(url, f.filename)
def upload(): f = request.files.get('upload') # Add more validations here extension = f.filename.split('.')[-1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail( message='Lütfen sadece resim yükleyiniz.(jpg, gif, png, jpeg)') try: f.save( os.path.join( "hastatakipsistemi/static/file/{}".format(session["username"]), f.filename)) except: os.mkdir("hastatakipsistemi/static/file/{}".format( session["username"])) f.save( os.path.join( "hastatakipsistemi/static/file/{}".format(session["username"]), f.filename)) url_for('uploaded_files', username=session["username"], filename=f.filename) # return upload_success call return upload_success('http://{}/files/{}/{}'.format( server_url, session["username"], f.filename))
def upload(): f = request.files.get('upload') basename, *extension = f.filename.split('.') #prevent danger.jpg.exe,etc if extension[-1].lower() not in ['jpg', 'gif', 'png', 'jpeg']\ and len(extension) == 1: return upload_fail(message='Image only!') #image_name' length f_fullname = basename[:10] + '_' + str(int( time() * 100)) + '.' + extension[0] f_dirname = os.path.join(app.config['UPLOADED_PATH'], str(current_user.id)) if not os.path.exists(f_dirname): os.makedirs(f_dirname) elif not os.access(f_dirname, os.W_OK): app.logger.error(' '.join(f_dirname, 'Non-writable!')) return upload_fail(message='Write error') f_path = os.path.join(app.config['UPLOADED_PATH'], str(current_user.id), f_fullname) f.save(f_path) image = UploadImage(image_path=f_path, image_name=f_fullname, user_id=current_user.id) try: db.session.add(image) db.session.commit() except: app.logger.error('database error') return upload_fail(message='Database error!') url = url_for('uploaded_files', filename=f_fullname) return upload_success(url=url)
def ckupload(): """CKEditor file upload""" error = '' url = '' if request.method == 'POST' and 'upload' in request.files: fileobj = request.files['upload'] fname, fext = os.path.splitext(fileobj.filename) rnd_name = '%s%s' % (gen_rnd_filename(), fext) filepath = os.path.join(current_app.static_folder, 'upload', rnd_name) # 检查路径是否存在,不存在则创建 dirname = os.path.dirname(filepath) if not os.path.exists(dirname): try: os.makedirs(dirname) except: error = 'ERROR_CREATE_DIR' elif not os.access(dirname, os.W_OK): error = 'ERROR_DIR_NOT_WRITEABLE' if not error: fileobj.save(filepath) url = url_for('static', filename='%s/%s' % ('upload', rnd_name)) else: error = 'post error' return upload_fail(message=error) return upload_success(url, rnd_name)
def upload(): file = request.files.get('upload') error = '' fname, fext = os.path.splitext(file.filename) if fext not in ['.jpg', '.gif', '.png', '.jpeg']: # 验证文件类型示例 return upload_fail('文件类型不匹配') rnd_name = '%s%s' % (gen_rnd_filename(), fext) #新的文件名称 filepath = os.path.join(current_app.config['UP_DIR'],rnd_name) dirname = os.path.dirname(filepath) #获取目录 if not os.path.exists(dirname): #检查目录是否存在 try: os.makedirs(dirname) os.chmod(dirname,'rw') except: error = 'ERROR_CREATE_DIR' elif not os.access(dirname, os.W_OK): error = 'ERROR_DIR_NOT_WRITEABLE' if not error: file.save(filepath) url = url_for('home.uploadfile',filename=rnd_name) return upload_success(url=url) # 返回upload_success调用 else: return upload_fail('上传失败')
def upload(): """The route function used by Ckeditor for uploading files. Get the file from the request object. Get its extension. If it's not an image format, return error. The reason being, this route is used for post images only. Create a random name for the file, and add the extension. Save the file with that name in the file system. Get the file url using uploaded_files() function above. Return the url and a success code. --- Returns ------- http response, file url """ f = request.files.get('upload') extension = f.filename.split('.')[-1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail(message='Image only!') random_hex = token_hex(8) filename = ''.join([random_hex, '.', extension]) f.save(os.path.join(current_app.config['UPLOADED_PATH'], filename)) url = url_for('posts.uploaded_files', filename=filename) return upload_success(url=url)
def upload_image(): f = request.files.get('upload') if not allowed_file(f.filename): return upload_fail('只允许图片') f.save(os.path.join(current_app.config['BLOG_UPLOAD_PATH'], f.filename)) url = url_for('.get_ck_image', filename=f.filename) return upload_success(url, f.filename)
def upload(): f = request.files.get('upload') extension = f.filename.split('.')[1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail(message='只能上传图片文件!') f.save(os.path.join(current_app.config['BLOG_PIC_PATH'], f.filename)) url = url_for('.uploaded_files', filename=f.filename) return upload_success(url=url)
def upload_for_ckeditor(): f = request.files.get('upload') if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail('Image only') f.save(os.path.join(app.config['UPLOAD_PATH'], f.filename)) url = url_for('get_file', filename=f.filename) return upload_success(url, f.filename)
def upload(): f = request.files.get('upload') # 获取上传文件对象 extension = f.filename.split('.')[1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail(message='只能上传图片(图片格式jpg, gif,png,jpeg)!') f.save(os.path.join(current_app.config['UPLOADED_PATH'], f.filename)) url = url_for('main.uploaded_files', filename=f.filename) return upload_success(url=url)
def upload(): f = request.files.get('upload') extension = f.filename.split('.')[-1].lower() if extension not in ['jpg', 'gif', 'jpeg', 'png']: return upload_fail(message='只支持图片上传') f.save(os.path.join(config.Config.paragraph_image, f.filename)) url = url_for('main.uploaded_files', filename=f.filename, _external=True) return upload_success(url=url)
def upload(): f = request.files.get('upload') image_filename = images.save(f) url = url_for('_uploads.uploaded_file', setname='images', filename=image_filename, _external=True) return upload_success(url=url)
def upload(): f = request.files.get('upload') extension = f.filename.split('.')[1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail(message='Image only!') f.save(os.path.join(app.config['UPLOADED_PATH'], f.filename)) url = url_for('uploaded_files', filename=f.filename) return upload_success(url=url)
def upload_pdf(): file = request.files.get('upload') if not ('.' in file.filename and \ file.filename.rsplit('.', 1)[1].lower() in \ current_app.config['ELIGIBLE_PDF']): return upload_fail('Can only upload a pdf') file.save(os.path.join(current_app.config['UPLOAD_PATH'], file.filename)) return upload_success(url_for('.get_file', filename=file.filename))
def upload(): f = request.files.get('upload') # 获取上传图片文件对象, 键必须为'upload' extensions = f.filename.split('.')[-1].lower() if extensions not in ['png', 'jpg', 'gif', 'jpeg']: return uploaded_fail(message='只能上传图片') f.save(os.path.join(app.config['UPLOAED'], f.filename)) url = url_for('uploads_files', filename=f.filename) return upload_success(url=url)
def upload_image(): f = request.files.get('upload') # 获取上传图片文件对象 # Add more validations here extension = f.filename.split('.')[1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: # 验证文件类型示例 return upload_fail(message='Image only!') # 返回upload_fail调用 f.save(os.path.join('/upload', f.filename)) url = url_for('uploaded_files', filename=f.filename) return upload_success(url=url) # 返回upload_success调用
def upload(): f = request.files.get('upload') # 获取上传图片文件对象 extension = f.filename.split('.')[1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: # 验证文件类型示例 return upload_fail(message='Image only!') # 返回upload_fail调用 UPLOAD_PATH = os.path.join(os.path.dirname(__file__), 'upload') f.save(os.path.join(UPLOAD_PATH, f.filename)) url = url_for('uploaded_files', filename=f.filename) return upload_success(url=url) # 返回upload_success调用
def upload(): f = request.files.get('upload') # 获取上传的文件 # todo: validations here extension = f.filename.split('.')[1].lower() if extension not in tuple('jpg jpe jpeg png gif svg bmp'.split()): return upload_fail(message='只能上传图片!') f.save(os.path.join('/static/img/upload/post_pic', f.filename)) url = url_for('blog.uploaded_files', filename=f.filename) return upload_success(url=url)
def edit_uploader(): f = request.files.get('upload') ext = os.path.splitext(f.filename)[1] if ext not in ['jpg', 'png', 'jpeg']: upload_fail(message='上传失败!') filename = random_filename(f.filename) f.save(os.path.join(app.config['UPLOAD_PATH'], filename)) url = url_for('get_file', filename=filename) return upload_success(url=url)
def upload_image(): f = request.files.get('upload') if not allowed_file(f.filename): return upload_fail('Image only!') extend_name = '.' + f.filename.split('.')[-1] uniq_name = str(uuid.uuid4()) + extend_name f.save(os.path.join(current_app.config['BLUELOG_UPLOAD_PATH'], uniq_name)) url = url_for('.get_image', filename=uniq_name) return upload_success(url, uniq_name)
def upload(): if not current_user.has_role('admin') : return upload_fail(message='Admin only!') f = request.files.get('upload') extension = f.filename.split('.')[1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail(message='Image only!') f.save(os.path.join(current_app.config['UPLOAD_FOLDER']+'posts/', f.filename)) return upload_success(url="/static/img/posts/%s"%f.filename)
def upload(): f = request.files.get("upload") # Add more validations here extension = f.filename.split(".")[1].lower() if extension not in ["jpg", "gif", "png", "jpeg"]: return upload_fail(message="Image only!") f.save(os.path.join("app/static/ckeditor_uploads", f.filename)) url = url_for("admin.uploaded_files", filename=f.filename) return upload_success(url=url) # return upload_success call
def upload(): f = request.files.get('main.upload') # 获取上传图片文件对象 # 验证图片格式 extension = f.filename.split('.')[1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: # 验证文件类型示例 return upload_fail(message='Image only!') # 返回upload_fail调用 f.save(os.path.join('/static/uploaded_files', f.filename)) # 上传时返回找不到图片的url,应该是这里不对 url = url_for('.uploaded_files', filename=f.filename) return upload_success(url=url)
def upload(): f = request.files.get('upload') if not allowed_file(f.filename): return upload_fail('Image only!') f.filename = time.strftime('%Y%m%d%H%M%S',time.localtime()) + '_' + f.filename f.save(os.path.join(current_app.config['UPLOADED_PATH'],f.filename)) url = url_for('main.uploaded_files', filename=f.filename) return upload_success(url,f.filename)
def ckeditor_upload(): f = request.files.get('upload') # Add more validations here extension = f.filename.split('.')[-1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail(message='Image only!') f.save(os.path.join(UPLOAD_PATH, f.filename)) url = url_for('administ.uploaded_files', filename=f.filename) return upload_success(url=url) # return upload_success call
def upload(): f = request.files.get('upload') extension = f.filename.split('.')[1].lower() if extension not in ['jpg', 'png', 'gif', 'jpeg']: return upload_fail(message='IMAGE ONLY') path = current_app.config['FILE_UPLOAD'] filename = resize_rename_img(image=f, filename=f.filename, path=path) url = url_for('user.show_upload', filename=filename) return upload_success(url=url, filename=filename)
def ckeditor_upload(): f = request.files.get('upload') extension = f.filename.split('.')[-1].lower() if extension not in ['jpg', 'gif', 'png', 'jpeg']: return upload_fail(message='Image only!') timestamp = re.sub('\.', '', str(time())) filename = str(current_user.id) + timestamp + f.filename f.save(os.path.join(current_app.config['UPLOADED_PATH'], filename)) url = url_for('main.uploaded_files', filename=filename) return upload_success(url=url)